Name workbook and save in a specific location

trevolly

Board Regular
Joined
Aug 22, 2021
Messages
124
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I've got a workbook that is a request form for engine runs at an airport. The engineers fill in the data and email it to us and then we email the completed request back to them. I've managed to set up vba so that when the form is filled in it saves the file and creates an email and attaches the excel workbook to it and fills in the recipients. The vba also creates a title for the email from the data in the form naming the email "Completed Engine Run Approval Form - GEZAW - 24/07/23" getting the date and aircraft registration from cells in the workbook.

The workbook is attached but the filename is "Engine Run Form Master.xlsm".
Capture.JPG


Is there anyway that the vba could name the workbook using the same format as the email subject and also save a copy of the workbook to a specific location? "\\gatwick.airport.local\Group9\2023 Airfield Inspection and Data\Aircraft High Powered Engine Runs\NEW\Pending Runs\"

Here's the vba I'm using.....
VBA Code:
Sub EmailBackToEngineers() 'Excel VBA to send mail.
Dim OutApp As Object
Dim OutMail As Object
Dim str1 As String
Dim str2 As String

Title = Range("C2")

str1 = [I4]
str2 = [I7]
str3 = [C6]

ThisWorkbook.SaveAs FileFormat:=xlOpenXMLWorkbookMacroEnabled

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

On Error Resume Next
With OutMail
.TO = str1 & ";" & str2
.Subject = "Pending Engine Run Approval Form" & " - " & Title & " - " & str3
.Body = "Hi," & vbLf & vbLf _
          & "Please find attached a Pending High Speed Engine Run approval form. Please fill in the final section on completion of the engine run and return to us no later than 2 hours." & vbLf & vbLf _
          & "Regards," & vbLf _
          & Application.UserName & vbLf & vbLf
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

As always any help is greatly appreciated guys.
 

Attachments

  • Capture.JPG
    Capture.JPG
    48.1 KB · Views: 11

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi,
as workaround:

first make sure your Title is also a good filename (no forbidden characters).
then You could create the savefullname like
saverfullname = YourPath & Tiltle & ".xlsm" ' Or xlsx depending on your wb type
make sure this is a correct fullname (check Backslashes)
then you can save Your Workbook with
ActiveWorkbook.SaveCopyAs savefullname
And change to
.Attachments.Add savefullname
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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