Garrett Bremer
Garrett Bremer

Reputation: 27

How to save a workbook using a value from a referenced cell as the file name?

I am trying to save a workbook with the value from a cell as the file name.

This code will save it as a specific file name,

ActiveSheet.SaveAs FileName:="C:\Desktop\temp1" 

I need to use a unique file name based on what is in the file.

I tried the following, but receive

runtime '1004' error

stating that the file could not be accessed.

Sub Save_Workbook()
' Saves workbook as filename

Dim FileName As String
Dim Path As String
Path = "C:\Desktop\"
FileName = Range("K5").Value & ".xlsm"
ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbookMacroEnabled

End Sub

Upvotes: 0

Views: 133

Answers (1)

Garrett Bremer
Garrett Bremer

Reputation: 27

The issue turned out to be the formatting of the contents of the target cell. Part of the string in the cell was 12:01. Once this was changed to 12.01, the issue was resolved.

Upvotes: 1

Related Questions