Pause macro until print job has finished

tony.reynolds

Board Regular
Joined
Jul 8, 2010
Messages
97
I have a macro as below that prints the sheet to a specific printer then it emails it to a recipiant selected from a userform "Email choice"

This macro is the macro in the userform for the first button on the user form "Email Choice"

I found that excel did not like running this if the print job from previous macro was not finished, so i had to add this wait time so it did not cause excell to crash. which is a real pain

Can someone help me either make it pause until print job is finished or help me eliminate the problem some other way?

First this is the end of the prevoius macro..

Code:
Application.ActivePrinter = "SHARP MX-2600N PCL6 on Ne00:"
                
    SENDTHISWORKBOOKVIAEMAIL.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
        
SENDTHISWORKBOOKVIAEMAIL.Activate

Application.ScreenUpdating = True
 
EmailChoice.Show

Then obviously the userform shows and the user selects on of the three options this being one of them, (the only difference between the three is the email address)

Code:
Private Sub Accounts_Click()
EmailChoice.Hide
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 8
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

Set emailthis = ActiveWorkbook
AONumber = Range("ACTION_ORDER_NUMBER").Value
AOSoldTo = Range("SOLDTOCOMPANY").Value
    
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
                
    On Error Resume Next
                                     
        With OutMail
        .To = "[EMAIL="accounts@xyz.com.au"]accounts@xyz.com.au[/EMAIL]"
        .Subject = "Action Order " & AONumber & " for " & AOSoldTo
        .Body = "Here is Action Order " & AONumber & " for " & AOSoldTo
        .Attachments.Add emailthis.FullName
        .Send
        End With
                            
    Set OutMail = Nothing
    Set OutApp = Nothing

   EmailChoice.Hide
   
   Windows("Action Order.xlsm").Activate
   Range("PLACED_BY").Value = "Tony Reynolds"
   ActiveWorkbook.Save
   ActiveWorkbook.Close
End Sub

any one that can clean up my code a bit and fix these issues would be great.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
above your modules place this declare

Code:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


use this to pause for n milliseconds

eg 1 second=1000milliseconds
Code:
Sleep 1000
 
Upvote 0
hey thanks diddi seems to work...

What exactly is kernal32? like what does this actually do
?
Is it pausing the macro until the printer drver thingo is free?

Thanks a stack
 
Upvote 0
can you manually set your print settings to spool, and the data should then print from the printer and not the PC
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top