我遇到了一个我创建的宏的问题。我正在根据用户的选择创建多个工作簿。但是,我想从我创建的每个文件中删除宏和工作表。我试过的代码阻止代码循环遍历范围,因为它似乎正在从我正在处理的原始文件中删除宏。下面是现在的代码,它创建了工作簿,因为我希望它们很好 但是 仍然包含用于触发宏 和 宏仍在其中。我需要保存每个没有它们的文件,并且原始模板文件不受影响。
Sub Button3_Click()
Dim MyCell As Range, MyRange As Range
Dim currentSheet As Excel.Worksheet
Dim LR As Long
Set currentSheet = ActiveSheet
LR = Range("A" & Rows.Count).End(xlUp).Row
Set MyRange = Range("A2:A" & LR).SpecialCells(xlCellTypeVisible)
For Each MyCell In MyRange
Worksheets("Front Sheet").Cells(5, 5) = MyCell.Value
ActiveWorkbook.RefreshAll
ActiveWorkbook.SaveAs Filename:="P:\Informatics\S&L scorecards\Clinical Scorecard Template\test\" & MyCell.Value & ".xls"
'here I want it to then delete the macro and a sheet called "Member"
Next MyCell
End Sub
请注意,我尝试过.xlsx文件类型,但也会停止循环 - 即使我使用Application.DisplayAlerts = False