I keep getting
when trying to run the a batch file with this script
SendEmail.vbs
PERSONAL.xlsb!Send_Range
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?
Code:
Run-time error '-2147467259 (80004005)': Method 'MailEnvelope' of object '_Worksheet' failed
Code:
wscript.exe "U:\Programming\Scripts\VBS Scripts\SendEmails.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?