Not able to initiate printer from checkbox

J

JanB

Hi all,

Hope someone is able to help.

I have made some selections in a checkbox and each check correspond to
a specific area that need to be printed. I can for some reason not get
the print part to work, see code below.

If StartSpecPrint = 1 Then
Print_specific_companies.Show
K = 1
Do While K < 3
jab = "ark" & K
If jab <> "" Then
K = K + 1
Else
knh = "Z" & K
tt = "n" & K
Sheets(jab).Select
ActiveSheet.PageSetup.PrintArea = knh

With ActiveSheet

Dato = Format(Date, "dd mm yyyy")
Tid = Format(Time, "hhmm")
' Defintion af datoformater.
Filename = ValgtSti & "\" &
ActiveSheet.Range(tt).Value & " " & Dato & " " & Tid & " " & ".pdf"

' Definition of where to save the file

Application.ActivePrinter = "CutePDF Writer on CPW2:"

.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", Collate:=True

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 4
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

' Excel waits 4 sec. for PDF to start

SendKeys Filename & "{ENTER}", True

' Using Sendkeys command to write filename in dialogbox

End With
K = K + 1
End If
Loop
Exit Sub
End If
 
J

Jim Cone

The loop continues until K = 3 then the sub is exited.
That is because jab is always <> "".
'--
Do While K < 3
jab = "ark" & K '<<<<<
If jab <> "" Then
K = K + 1
Else
PrintOut
End If
Loop
Exit Sub
'--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/ExtrasForXL

..
..
..

"JanB" <[email protected]>
wrote in message
Hi all,
Hope someone is able to help.
I have made some selections in a checkbox and each check correspond to
a specific area that need to be printed. I can for some reason not get
the print part to work, see code below.

If StartSpecPrint = 1 Then
Print_specific_companies.Show
K = 1
Do While K < 3
jab = "ark" & K
If jab <> "" Then
K = K + 1
Else
knh = "Z" & K
tt = "n" & K
Sheets(jab).Select
ActiveSheet.PageSetup.PrintArea = knh

With ActiveSheet

Dato = Format(Date, "dd mm yyyy")
Tid = Format(Time, "hhmm")
' Defintion af datoformater.
Filename = ValgtSti & "\" &
ActiveSheet.Range(tt).Value & " " & Dato & " " & Tid & " " & ".pdf"

' Definition of where to save the file

Application.ActivePrinter = "CutePDF Writer on CPW2:"

.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", Collate:=True

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 4
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

' Excel waits 4 sec. for PDF to start

SendKeys Filename & "{ENTER}", True

' Using Sendkeys command to write filename in dialogbox

End With
K = K + 1
End If
Loop
Exit Sub
End If
 
Top