Keegan4123
New Member
- Joined
- Mar 30, 2022
- Messages
- 29
- Office Version
- 2016
- Platform
- Windows
I have a file that is generated daily, so name and file change on a regular basis.
I have set up a macro that organizes the file, and adds a button to email.
The button is then linked to another macro set up to send the document as an attachment when emailed.
The email macro is a template online, that allows one click sending. I don't have to go to outlook and then send the email, no popups are generated.
However it uses a source of ThisWorkbook.fullname, I have the macro saved in my personal file so it can be used on the various other files. I have tried updating to activeworkbook.fullname, but it continues to throw errors. Not sure how to get this to work with the active workbook rather then the personal work book. Line is highlighted below in red.
Sub SendEmail_Example1()
Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)
EmailItem.To = "Hi@gmail.com"
EmailItem.CC = "hello@gmail.com"
EmailItem.BCC = "hhhh@gmail.com"
EmailItem.Subject = "Test Email From Excel VBA"
EmailItem.HTMLBody = "Hi," & vbNewLine & vbNewLine & "This is my first email from Excel" & _
vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"VBA Coder"
Source = ThisWorkbook.FullName
EmailItem.Attachments.Add Source
EmailItem.Send
End Sub
I have set up a macro that organizes the file, and adds a button to email.
The button is then linked to another macro set up to send the document as an attachment when emailed.
The email macro is a template online, that allows one click sending. I don't have to go to outlook and then send the email, no popups are generated.
However it uses a source of ThisWorkbook.fullname, I have the macro saved in my personal file so it can be used on the various other files. I have tried updating to activeworkbook.fullname, but it continues to throw errors. Not sure how to get this to work with the active workbook rather then the personal work book. Line is highlighted below in red.
Sub SendEmail_Example1()
Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)
EmailItem.To = "Hi@gmail.com"
EmailItem.CC = "hello@gmail.com"
EmailItem.BCC = "hhhh@gmail.com"
EmailItem.Subject = "Test Email From Excel VBA"
EmailItem.HTMLBody = "Hi," & vbNewLine & vbNewLine & "This is my first email from Excel" & _
vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"VBA Coder"
Source = ThisWorkbook.FullName
EmailItem.Attachments.Add Source
EmailItem.Send
End Sub