我新建了一个xlsx的excel 文件,
在file-option--trust center--macro settings 里面选了enable all macros 和trust access to the vba project object model
然后按alt+F11
在Thisworkbook里面加了如下代码,用于保存时命名
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Name As String
With ThisWorkbook
Name = Worksheets("Sheet1").Cells(3, 5).Value & ".xlsx"
.SaveCopyAs Name
End With
End Sub
但点save后提示
the following features cannot be saved in macro-free workbooks
vb project
to save a file with these features click no and then choose a macro-enabled file type in the file type list.
to continue saving as a macro-free workbook, click yes
------解决方案--------------------------------------------------------
EXCEL 启用宏的工作薄 必须保存为.xlsm 宏才有效 如果保存为.xlsx 宏是无法使用的
请查看您excel表格的的拓展名