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..
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)
any one that can clean up my code a bit and fix these issues would be great.
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.