Hi guys!
ATTENTION NEWBIE IN ACTION
So i recently started working with excel and VBA at work, and got hooked right away! However, now i'm standing in neck deep in spreadsheet(... get it?) and need some fresh eyes to point out my error. The goal is to have a macro that once executed, will delete a single sheet, then e-mail the workbook as an attachment. However, at the moment, it only deletes the sheet from the original workbook, and not the attachment...
(Credit to Excel Automation - Ron de Bruin for showing me the way of the spreadsheet)
Sub MyBrokenSub()
Dim MailApp As Object
Dim MailCreate As Object
Dim WB1 As Workbook
Set MailApp = CreateObject("Outlook.Application")
Set MailCreate = OutApp.CreateItem(0)
Set WB1 = ActiveWorkbook
With WB1
Sheets("MySheet").Delete
End With
On Error Resume Next
With OutMail
.to = ”something@something.totallyalegitdomain"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add WB1.FullName
.Send
End With
On Error GoTo 0
Set MailApp = Nothing
Set MailCreate = Nothing
End Sub
ATTENTION NEWBIE IN ACTION
So i recently started working with excel and VBA at work, and got hooked right away! However, now i'm standing in neck deep in spreadsheet(... get it?) and need some fresh eyes to point out my error. The goal is to have a macro that once executed, will delete a single sheet, then e-mail the workbook as an attachment. However, at the moment, it only deletes the sheet from the original workbook, and not the attachment...
(Credit to Excel Automation - Ron de Bruin for showing me the way of the spreadsheet)
Sub MyBrokenSub()
Dim MailApp As Object
Dim MailCreate As Object
Dim WB1 As Workbook
Set MailApp = CreateObject("Outlook.Application")
Set MailCreate = OutApp.CreateItem(0)
Set WB1 = ActiveWorkbook
With WB1
Sheets("MySheet").Delete
End With
On Error Resume Next
With OutMail
.to = ”something@something.totallyalegitdomain"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add WB1.FullName
.Send
End With
On Error GoTo 0
Set MailApp = Nothing
Set MailCreate = Nothing
End Sub