【发布时间】:2016-06-17 17:45:14
【问题描述】:
I am getting error while running the below vb script to run the personal macro stored on an macro enabled workbook. `"Method 'Sheets' of object '_Global' failed"`
'Open an instance of Excel
Set objExcel=CreateObject("Excel.Application")
objExcel.Visible=True
设置 objWorkbook=objExcel.Workbooks.Open("C:\Microsoft\Excel\XLSTART\PERSONAL.XLSB") '调用宏 objExcel.Run "PERSONAL.XLSB!PLAN"
' Macro which is being called by the above script
Option Explicit
Public NewCols As Long ' EGPO
Dim i As Long
Dim colx As Long
Sub PLAN()
Application.ScreenUpdating = False
Call PLAN
Application.ScreenUpdating = True
End Sub
Private Sub LatestCRDTwo()
On Error Resume Next
Dim wb As Workbook
Dim P As String, Q As String
P = "Pass\Fail"
Q = "Test Cases"
Application.ScreenUpdating = False
' 将使用任何启用宏的工作簿
设置 wb = ActiveWorkbook
With Sheets("EGPO")
Sheets("EGPO").Select
NewCols = .UsedRange.Columns.Count
.AutoFilterMode = False
' Add columns starting at column 4 and insert columns at every 2nd column
For colx = 4 To 40 Step 2
NewCols = .UsedRange.Columns.Count
Columns(colx).Insert Shift:=xlToRight
NewCols = NewCols + 1
Next colx
End With
On Error Resume Next
'Below "With statements" is to copy the values in the inserted columns
With Sheets("EGPO")
Sheets("EGPO").Select
NewCols = .UsedRange.Columns.Count
' 循环粘贴值 对于 i = 4 到 NewCols 步骤 2 如果 wb.Worksheets("EGPO").Cells(1, 1).Value = "" 那么 wb.Worksheets("EGPO").Cells(2, i) = P wb.Worksheets("EGPO").Cells(2, i).Interior.ColorIndex = 15 wb.Worksheets("EGPO").Cells(1, i) = Q 万一 新列 = 新列 + 1 接下来我
End With
On Error Resume Next
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
错误可能在您正在调用的宏中。你能把它的内容贴在这里吗?
-
@Isaac - 我在帖子中的 vb 脚本下方添加了宏代码,谢谢