将 VBA 代码转换为 Vbscript [英] Convert VBA code to Vbscript

查看:39
本文介绍了将 VBA 代码转换为 Vbscript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在宏中使用以下代码删除excel中的空白行.你能帮我把它转换成 Vbscript 吗?

I am using the below code in macro to delete blank rows in excel. Can you please help me in converting the same into Vbscript?

Columns("A:A").Select
   Selection.SpecialCells(xlCellTypeBlanks).Select
   Selection.EntireRow.Delete

等待您的宝贵回复.

推荐答案

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.

这篇关于将 VBA 代码转换为 Vbscript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆