VBA code to save an xlsm file based on specific naming

fishandtril

New Member
Joined
Nov 15, 2022
Messages
15
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi

I am trying to automate the SaveAs function to apply the naming based on specific criteria in my worksheet. My code works but I keep getting messages that it needs to be saved in xlsm format which I thought I solved in the code. The code then fails when I select and option on the message. Can anyone help me figure out what I am doing wrong. Thanks

VBA Code:
Sub SaveAsVessel()

Dim path As String
path = "M:\Middle Office\Internal Deal Pricing\Blend Change Shipments\"

Dim fname As String
fname = Range("E5")

With ActiveWorkbook
    .SaveAs filename:=path & fname, FileFormat:=51
        .Close
End With
End Sub

1672979203028.png
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello. Turning off alerts should bypass the alert you receive.

VBA Code:
Sub SaveAsVessel()

Dim path As String
path = "M:\Middle Office\Internal Deal Pricing\Blend Change Shipments\"

Dim fname As String
fname = Range("E5")

'temporarily turn off alerts
Application.DisplayAlerts = False
With ActiveWorkbook
    .SaveAs Filename:=path & fname, FileFormat:=51
    .Close
End With
'turn alerts back on before end sub
Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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