简体   繁体   English

通过VBA宏保存具有特定单元名称的xlsm文件

[英]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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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