View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JanB[_2_] JanB[_2_] is offline
external usenet poster
 
Posts: 6
Default 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