且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 VBA 代码转换为 Vbscript

更新时间:2023-02-16 22:20:26

VBScript 不像 VBA 运行时环境那样提供隐式父对象,因此您需要使一切都显式:

VBScript doesn't provide implicit parent objects like the VBA runtime environment does, so you need to make everything explicit:

Set xl = CreateObject("Excel.Application")
Set wb = xl.Workbooks.Add
Set ws = wb.Sheets(1)

ws.Columns("A:A").Select
...

此外,VBScript 无法识别 VBA 命名常量,因此您需要使用数值:

Also, VBScript doesn't recognize VBA named constants, so you need to either use the numeric value:

...
xl.Selection.SpecialCells(4).Select
...

或在脚本中定义常量:

Const xlCellTypeBlanks = 4
...
xl.Selection.SpecialCells(xlCellTypeBlanks).Select
...

有关将 VBA 转换为 VBScript 的更多信息,请参阅此处.

See here for more information about translating VBA to VBScript.