我正在尝试编写代码,允许我根据现有工作簿中单元格的值创建新文件夹。从那里,将文件的副本保存在新创建的工作簿中,并使用基于单元格值的名称以及添加的一些附加文本。请参阅下面的代码并让我知道我失败的地方。该错误突出显示“ActiveWorkBook.SaveCopyAs”行。
Dim path As String
Dim filename1 As String
Dim filename2 As String
path = ThisWorkbook.path & "\"
filename1 = Worksheets("Instructions").Range("B1").Text & " Initial Comment Matrix"
filename2 = Worksheets("Instructions").Range("B1").Text
MkDir filename2
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs ThisWorkbook.path & filename2 & filename1 & ".xlsm"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox ("DONE")
像这样:
Dim v As String, path As String, wb As Workbook
Set wb = ThisWorkbook
v = wb.Worksheets("Instructions").Range("B1").text
path = wb.path & "\" & v
If Dir(path, vbDirectory) = "" Then MkDir path 'use the full path
Application.DisplayAlerts = False
wb.SaveCopyAs path & "\" & v & " Initial Comment Matrix.xlsm"
Application.DisplayAlerts = True