用于将宏插入excel文件的VB脚本

问题描述 投票:0回答:1

在某些情况下,我们需要以编程方式将宏插入到Excel工作表中。我找到了一个VB脚本,它将特定的宏插入到上面提到的excel表中。

excel vba vbscript
1个回答
0
投票
Set objExcel = CreateObject("Excel.Application")
strPath = WScript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile) 
excelLocation = strFolder & "\GeneratedReport.xls"
macroVBSLocation = strFolder & "\sendMailModule.bas"
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Open(excelLocation)
       objWorkbook.VBProject.VBComponents.Import macroVBSLocation
objWorkbook.Save
objExcel.Quit

excelLocation指向excel将出现的位置。 macroVBSLocation指向宏将存在的位置。

© www.soinside.com 2019 - 2024. All rights reserved.