我编写了一个绑定到按钮的宏,用于将excel工作表导出到新工作簿并保存。宏在保存之前删除了所有按钮。宏工作正常,工作表生成并保存,但在关闭之前,我得到了一个错误,我不知道为什么!
Sub Export_IssuesLog()
Dim answer As Integer
Dim PathName As String
answer = MsgBox("Do you want to export the issues log?" _
& Chr(13) & Chr(13) & Chr(10) & "Note: This macro automatically overwites versions with the same Revision Number. Please ensure the revision number is updated correctly.", vbQuestion + vbYesNo)
If answer = vbYes Then
PathName = ThisWorkbook.Path & "\" & Range("Proj_no").Value & "_" & Range("Client_short").Value & "_" & Range("Facility_short").Value & "_IssuesLog_REV-" & Range("B4").Value & ".xlsx"
ActiveSheet.Copy
For Each btn In ActiveSheet.Shapes
If btn.AutoShapeType = msoShapeStyleMixed Then btn.Delete
Next
ActiveWorkbook.SaveAs Filename:=PathName
ActiveWorkbook.Close SaveChanges:=False
Else
Exit Sub
End If
End Sub
如果我删除这段代码(它确实成功地删除了按钮),宏将完美地工作。
For Each btn In ActiveSheet.Shapes
If btn.AutoShapeType = msoShapeStyleMixed Then btn.Delete
Next
如果我包含了这段代码,它给我的错误是在ActiveWorkbook.SaveAs行上。它给我一个运行时错误“1004”-对象“_workbook”的方法“SaveAs”失败。
问题是,它确实保存了工作簿!我不知道我做错了什么!
1条答案
按热度按时间7cjasjjr1#
引用对象
Option Explicit
。