# VBA code to save an xlsm file based on specific naming



## fishandtril (Jan 5, 2023)

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


```
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
```


----------



## breynolds0431 (Jan 6, 2023)

Hello. Turning off alerts should bypass the alert you receive.


```
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
```


----------



## fishandtril (Jan 6, 2023)

Thanks. That works perfectly.


----------

