就目前而言,我已经将它写在代码在原始文件所在的文件夹中创建一个文件的位置。创建文件后,我希望将其 wbBK2 定义为刚刚创建的文件。我想使用相同的代码来创建文件,减去 SaveAs 选项会起作用,但它似乎不喜欢该对象。
有什么原因吗?出于所有预期目的,它应该直接指向文件,但似乎不同意......有人能看到我犯的错误吗?
Option Explicit
Sub OpenOrderReportExport()
Dim wsJL As Worksheet 'Jobs List
Dim wsPOT As Worksheet 'PO Tracking
Dim wsTNO As Worksheet 'Tel-Nexx OOR
Dim wbBK2 As Workbook 'New Workbook
Dim wsWS1 As Worksheet 'Sheet1
Dim wsWS2 As Worksheet 'Sheet2
Dim wsWS3 As Worksheet 'Sheet3
Dim CurrentFile As String, NewFileType As String, NewFile As String, Dir As String
Set wsJL = Sheets("Jobs List") 'Jobs List
Set wsPOT = Sheets("PO Tracking") 'PO Tracking
Set wsTNO = Sheets("Tel-Nexx OOR") 'Tel-Nexx OOR
Set wbBK2 = Workbooks.Add 'New Workbook
Set wsWS1 = wbBK2.Sheets("Sheet1") 'Sheet1
Set wsWS2 = wbBK2.Sheets("Sheet2") 'Sheet2
Set wsWS3 = wbBK2.Sheets("Sheet3") 'Sheet3
Application.ScreenUpdating = False ' Prevents screen refreshing.
CurrentFile = ThisWorkbook.FullName
NewFileType = "Excel Files 2007 (*.xlsx)"
Dir = ThisWorkbook.path
wbBK2.SaveAs Dir & Application.PathSeparator & "Open Order Report -" & Format(Date, "mm-dd-yyyy") & ".xlsx"
Set wbBK2 = Dir & Application.PathSeparator & "Open Order Report -" & Format(Date, "mm-dd-yyyy") & ".xlsx"
MsgBox wbBK2
End Sub