在某些情况下,我们需要以编程方式在Excel工作表中插入宏。我找到了一个VB脚本,该脚本会将特定的宏插入到上述excel工作表中。
答案 0 :(得分: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指向将存在宏的位置。