这是我的代码,我正在尝试,它可以在 PC 上运行,但不能在 Mac 上运行,运行此代码并创建一个 Excel 表,命名,添加一个选项卡,更改所述选项卡的颜色,更改名称所述选项卡,然后将数据转置,同时保持单元格的格式以及单元格的宽度和高度到新的工作表。
这在 PC 上有效....但是当我使用 Mac 时,它没有。
我进入参考文献,这就是我所看到的。
我看到 Ref 编辑控件,并且缺少 Microsoft 脚本运行时。我禁用了两者,脚本仍然给我一个错误:
wbBK2.SaveAs Dir & Application.PathSeparator & "Open Order Report -" & Format(Date, "mm-dd-yyyy") & ".xlsx"
该错误发生在(Date, "mm-dd-yyyy")
特别是日期部分。我无法弄清楚为什么会诚实地发生这种情况。如果有人可以仔细阅读并给我答案和解决方案,将不胜感激。
我得到的错误是Error '9 Subscript Out Of Range
我看不出这个错误只出现在 Mac 而不是 PC 上的原因。
Option Explicit
Sub OpenOrderReportExport()
Dim wsJL As Worksheet 'Jobs List
Dim wsPOT As Worksheet 'PO Tracking
Dim wsTNO As Worksheet 'Tel-Nexx OOR
Dim wsDOO As Worksheet 'Dakota OOR
Dim wbBK1 As Workbook 'Open Order Report
Dim wbBK2 As Workbook 'New Workbook
Dim wsWS1 As Worksheet 'Sheet1
Dim wsWS2 As Worksheet 'Sheet2
Dim wsWS3 As Worksheet 'Sheet3
Dim wsWS4 As Worksheet 'Sheet4
Dim CurrentFile As String, NewFileType As String, NewFile As String, Dir As String, lastrow As Long
Set wsJL = Sheets("Jobs List") 'Jobs List
Set wsPOT = Sheets("PO Tracking") 'PO Tracking
Set wsTNO = Sheets("Tel-Nexx OOR") 'Tel-Nexx OOR
Set wsDOO = Sheets("Dakota OOR") 'Dakota OOR
Set wbBK1 = ThisWorkbook
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 & Application.PathSeparator & "Reports"
wbBK2.SaveAs Dir & Application.PathSeparator & "Open Order Report -" & Format(Date, "mm-dd-yyyy") & ".xlsx"
Sheets.Add After:=Sheets(Sheets.Count)
Set wsWS4 = wbBK2.Sheets("Sheet4") 'Sheet4
With wbBK2
Dim Sht As Worksheet
For Each Sht In Worksheets
Sht.Tab.Color = 255
Next
End With
Sheets("Sheet1").Name = "Jobs List"
Sheets("Sheet2").Name = "PO Tracking"
Sheets("Sheet3").Name = "Dakota OOR"
Sheets("Sheet4").Name = "Tel-Nexx OOR"
With wbBK1
'Jobs List Export
lastrow = wsJL.Range("B" & Rows.Count).End(xlUp).Row
wsJL.Range("A2:N2").Copy
wsWS1.Range("A1").PasteSpecial xlPasteAll
wsJL.Range("A3:N" & lastrow).Copy
wsWS1.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats
wsWS1.Range("A2").PasteSpecial xlPasteColumnWidths
wsJL.Range("B3:N" & lastrow).Copy
wsWS1.Range("B2").PasteSpecial xlPasteFormats
wsWS1.Columns("A").Delete
'Tel-Nexx Export
lastrow = wsTNO.Range("B" & Rows.Count).End(xlUp).Row
wsTNO.Range("A2:Q2").Copy
wsWS2.Range("A1").PasteSpecial xlPasteAll
wsTNO.Range("A3:Q" & lastrow).Copy
wsWS2.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats
wsWS2.Range("A2").PasteSpecial xlPasteColumnWidths
wsTNO.Range("B3:Q" & lastrow).Copy
wsWS2.Range("B2").PasteSpecial xlPasteFormats
wsWS2.Columns("A").Delete
'Dakota Export
lastrow = wsDOO.Range("B" & Rows.Count).End(xlUp).Row
wsDOO.Range("A2:O2").Copy
wsWS3.Range("A1").PasteSpecial xlPasteAll
wsDOO.Range("A3:O" & lastrow).Copy
wsWS3.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats
wsWS3.Range("A2").PasteSpecial xlPasteColumnWidths
wsDOO.Range("B3:O" & lastrow).Copy
wsWS3.Range("B2").PasteSpecial xlPasteFormats
wsWS3.Columns("A").Delete
'PO Tracking Export
lastrow = wsPOT.Range("B" & Rows.Count).End(xlUp).Row
wsPOT.Range("A2:K2").Copy
wsWS4.Range("A1").PasteSpecial xlPasteAll
wsPOT.Range("A3:K" & lastrow).Copy
wsWS4.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats
wsWS4.Range("A2").PasteSpecial xlPasteColumnWidths
wsPOT.Range("B3:K" & lastrow).Copy
wsWS4.Range("B2").PasteSpecial xlPasteFormats
wsWS4.Columns("A").Delete
End With
With wsWS1
.Activate
.Range("A1").Select
End With
End Sub