我在将以下VBA代码转换为VBS时遇到问题。我是编写VBS的新手,所以非常感谢任何帮助。
Public Sub Details()
Set xl = New Excel
Set wb = xl.obj_.Workbooks.Add
Const xlWhole = 1
Const xlPart = 2
Const ColField = "Combined Field2"
Dim k, bfind
Set bfind = x1.ActiveSheet.UsedRange.Cells.Find(what:=ColField, lookat:=xlWhole)
k = bfind.Column
Columns(k).Delete
'create pivot
x1.ActiveSheet.Activate
Set PCache = x1.ActiveWorkbook.PivotCaches.Create(SourceType:=1, SourceData:=Range("A1").CurrentRegion.Address)
x1.Worksheets.Add
x1.ActiveSheet.Name = "Pivot"
x1.ActiveWindow.DisplayGridlines = False
Set pt = x1.ActiveSheet.PivotTables.Add(PivotCache:=PCache, TableDestination:=Range("A1"), TableName:="PivotTable1")
With pt
.InGridDropZones = True
.RowAxisLayout xlTabularRow
.DisplayContextTooltips = False
.ShowDrillIndicators = False
End With
End Sub
答案 0 :(得分:1)
Set xl = New Excel
我不认为VBScript可以像这样创建一个Excel实例。我不做VBScript,所以可能,但我总是看到Excel实例化了这样的东西:
' 1a. Get an existing Excel instance...
Set Excel = GetObject(, "Excel.Application")
' 1b. Or, create one. Make it visible for testing.
Set Excel = CreateObject("Excel.Application")
Excel.Visible = True
(摘自this answer)