将 Excel VBA 代码注入并执行到从外部源接收的电子表格中 [英] Inject and execute Excel VBA code into spreadsheet received from external source

查看:30
本文介绍了将 Excel VBA 代码注入并执行到从外部源接收的电子表格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式(在 vbscript 或命令行或其他方式中)将 VBA 代码注入我从 FTP 站点获取的工作簿中,然后在工作簿上执行宏.全部自动化.没有用户交互.

I would like to programatically (in vbscript or command line or whatever) inject VBA code into a workbook I get from an FTP site and then execute the macro on the workbook. All automated. No user interaction.

我在文本文件中定义了 VBA 代码.

I have the VBA code defined in a text file.

推荐答案

还没有机会尝试这个,但我认为这会满足我的需求.

Haven't had a chance to try this yet but i think this will do what i need.

Set objExcel = CreateObject("Excel.Application") 
objExcel.Visible = True 
objExcel.DisplayAlerts = False 
Set  objWorkbook = objExcel.Workbooks.Open("C:scripts	est.xls") 
   Set xlmodule = objworkbook.VBProject.VBComponents.Add(1)  
   strCode = _ 
   "sub test()" & vbCr & _ 
   "   msgbox ""Inside the macro"" " & vbCr & _ 
   "end sub" 
   xlmodule.CodeModule.AddFromString strCode 
objWorkbook.SaveAs "c:scripts	est.xls" 
objExcel.Quit 

这篇关于将 Excel VBA 代码注入并执行到从外部源接收的电子表格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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