Excel 2007 VBA to Save File and EMail as Attachment

cvincent

Board Regular
Joined
Aug 28, 2011
Messages
66
I am having trouble with this macro. The file is a form the user completes (v1), then clicks the macro to submit (v2). In doing so, a new version is created. The user goes back to his form, and has a button he can clear the form and submit a new request. But now the form is actually named (v2) instead of the actual original form name. Can you please advise? Thank you.

Sub Send()
' Send Macro
ActiveWorkbook.Save

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
' Change the mail address and subject in the macro before you run it.
With OutMail
.To = "email address"
.CC = ""
.BCC = ""
.Subject = "Request Form"
.Body = "Please process the attached Request Form." & Chr(10) & Chr(10)
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
It appears you're using Ron de Bruin's code Example 1 shown at this link as a basis for your macro.
Mail the whole workbook

On the same page, he shows an Example 2 which looks like a better starting point for what you describe.

In the code you posted I'm not seeing where v1 is saved as v2. Perhaps that is happening before this macro is called?
If that's the case, you'll want to reorganize the parts so the copy of the workbook is made prior to the renaming v1 to v2.
 
Upvote 0
Thank you Jerry. I actually think I may have found the problem, as strange as it may seem. I had named my form using "v1". Just on a whim, I removed that part of the name, and now it seems to be working ok. Could it be that the problem was in the file name?
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,860
Members
449,472
Latest member
ebc9

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