Running Macro using Task Scheduler- Getting Run Time Error

dmcgetti

Board Regular
Joined
Feb 16, 2015
Messages
66
I keep getting
Code:
Run-time error '-2147467259 (80004005)': Method 'MailEnvelope' of object '_Worksheet' failed
when trying to run the a batch file with this script
Code:
wscript.exe "U:\Programming\Scripts\VBS Scripts\SendEmails.vbs"
SendEmail.vbs
Code:
Option Explicit

Sub ExcelMacroExample() 
  Dim xlApp 
  Dim xlBook 


  Set xlApp = CreateObject("Excel.Application") 
  Set xlBook = xlApp.Workbooks.Open("U:\SalesDB\NewSales.xlsx") 
  xlapp.workbooks.open("C:\Users\dmcgettigan\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.xlsb")
  xlApp.Run "PERSONAL.xlsb!Send_Range"
  xlApp.Quit 




  Set xlBook = Nothing 
  Set xlApp = Nothing 
End Sub

PERSONAL.xlsb!Send_Range

Code:
Sub Send_Range()ActiveWorkbook.RefreshAll
ActiveWorkbook.Save
Worksheets(3).Activate
Worksheets(3).Columns("A:G").AutoFit
ActiveSheet.Range("A1:G89").Select
ActiveWorkbook.EnvelopeVisible = False
With ActiveSheet.MailEnvelope
      .Introduction = ""
      .Item.To = xxx@xxx.com"
      .Item.Subject = "Sales Numbers"
      .Item.Send
   End With
ActiveWorkbook.Save
Worksheets(4).Activate
Worksheets(4).Columns("A:E").AutoFit
   ActiveSheet.Range("A49:E82").Select
   With ActiveSheet.MailEnvelope
      .Introduction = ""
      .Item.To = "xxx@xxx.com"
      .Item.Subject = "Return Numbers"
      .Item.Send
   End With
ActiveWorkbook.Save
Worksheets(1).Activate
Worksheets(1).Columns("A:L").AutoFit
   ActiveSheet.Range("A1:L46").Select
   With ActiveSheet.MailEnvelope
      .Introduction = ""
      .Item.To = "xxx@xxx.com"
      .Item.Subject = "Fill Rate"
      .Item.Send
   End With
   ActiveWorkbook.Save
 End Sub

When I search the internet, it seems the only solution I have found is to save the file before emailing but that is not working for me, any ideas?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,223,699
Messages
6,173,907
Members
452,536
Latest member
Chiz511

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