VBA Help - Attaching spreadsheet to e-mail + Autosave with name change

rosswild

New Member
Joined
Aug 24, 2017
Messages
1
Hello,

I have the following code which I am using so people can e-mail the workbook they are using to a specified address.

That bit works perfectly.

I then added a save function as I wanted the document to be renamed before saving based on a cell in the document. It is being saved in the current location as I didn't want to specify a location as different users/computers will be using the document.

Again this appears to be working as the document is renamed (I can see it's new name at the top of the excel doc), although it doesn't appear in my folder as a new saved document.

The macro then runs through with no errors but then doesn't attach the document.

I can't see what I am doing wrong. Any suggestions would be greatly appreciated.

Code:
Sub Mail_workbook_Outlook_1()
   
   
    answer = MsgBox("You are about to e-mail the requisition to the buying department, do you wish to proceed?", vbYesNo)
If answer = vbNo Then Exit Sub
If Range("A24").Value = "Checks - Please resolve the problems below" Then
  MsgBox "Error - You have not completed all the required feilds. Please resolve before sending."
  Exit Sub
End If
 
 Dim wbname As String
 Dim pathONLY, filePATH, fileONLY As String
 filePATH = ThisWorkbook.FullName
 fileONLY = ThisWorkbook.Name
 pathONLY = Left(filePATH, Len(filePATH) - Len(fileONLY))
 wbname = Sheets("Hidden").Range("B10").Value
 On Error Resume Next
 ActiveWorkbook.SaveAs Filename:=pathONLY & wbname & ".xlsm"
 
 
 Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    With OutMail
        .To = ThisWorkbook.Sheets("Hidden").Range("B2").Value
        .CC = ThisWorkbook.Sheets("Hidden").Range("B9")
        .BCC = ""
        .Subject = ThisWorkbook.Sheets("Hidden").Range("B7").Value
        .Body = ThisWorkbook.Sheets("Hidden").Range("B8").Value
        .Attachments.Add ActiveWorkbook.FullName
       
        .Display
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
Thank you
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,563
Messages
6,125,554
Members
449,237
Latest member
Chase S

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