ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Not able to initiate printer from checkbox (https://www.excelbanter.com/excel-programming/443468-not-able-initiate-printer-checkbox.html)

JanB[_2_]

Not able to initiate printer from checkbox
 
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

Jim Cone[_2_]

Not able to initiate printer from checkbox
 

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"
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


All times are GMT +1. The time now is 01:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com