|
发表于 2024-7-3 09:49
来自手机
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 lss001 于 2024-7-3 10:05 编辑
wangnangj 发表于 2024-7-2 16:10
您好,这个能用文本文档编辑成vbs吗?
https://blog.csdn.net/weixin_30889885/article/details/97699269
可参考以上链接
把以下代码复制到记事本,保存为vbs即可
Call RunStr
Sub RunStr()
Set eApp = CreateObject("excel.application") '创建excel对象
Set wb = eApp.Workbooks.Add '添加表格
Set vbaBas = wb.VBProject.VBComponents.Add(1) '添加模块
'winApi函数
str1 = "Private Declare Sub keybd_event Lib ""user32.dll"" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)"
With vbaBas.CodeModule '添加模块代码
.InsertLines 1, str1 '添加winapi函数
.InsertLines 3, "Sub myMacro()"
.InsertLines 4, " keybd_event &H5B, 0, 0, 0"
.InsertLines 5, " keybd_event &H12, 0, 0, 0"
.InsertLines 6, " keybd_event &H47, 0, 0, 0"
.InsertLines 7, " keybd_event &H47, 0, 2, 0"
.InsertLines 8, " keybd_event &H12, 0, 2, 0"
.InsertLines 9, " keybd_event &H5B, 0, 2, 0"
.InsertLines 11, "End Sub"
End With
eApp.Run "myMacro" '执行代码
wb.VBProject.VBComponents.Remove vbaBas '删除模块
wb.Saved = True '忽略保存提示!
wb.Close '关闭表格
eApp.Quit '退出excel
Set vbaBas = Nothing '释放对象
Set wb = Nothing
Set eApp = Nothing
End Sub |
|