简体   繁体   中英

Saving a xlsm file with the name of specific cell through vba macro

I'm trying to make a button that saves my workbook with the name of a specific cell from one of its own sheets.

The cell that I'm getting the name from is gonna change it's value each week. I get the error:

Run-time error '1004':
Method 'SaveAs' of object'_Workbook' failed

Here is the code:

Private Sub Save_file_Click()
Dim path As String
Dim filename1 As String
Dim ws As Worksheet

Set ws = ActiveWorkbook.Sheets("Fejlregistrering")

path = "C:\Users\JOHLA\Desktop\Yield ark\"
filename1 = ws.Range("D5").Text
ActiveWorkbook.SaveAs path & filename1 & ".xlsm", FileFormat =  xlOpenXMLWorkbookMacroEnabled


End Sub

//Johan

Change

ActiveWorkbook.SaveAs path & filename1 & ".xlsm", FileFormat = xlOpenXMLWorkbookMacroEnabled

to

ActiveWorkbook.SaveAs Filename:=(path & filename1 & ".xlsm"), FileFormat:=xlOpenXMLWorkbookMacroEnabled

尝试以下

ActiveWorkbook.SaveAs Filename:=path & filename1, FileFormat:=xlOpenXMLWorkbookMacroEnabled

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM