在读写模式下使用 VBScript 打开多个 Excel 文件
Open Multiple Excel Files using VBScript in Read and write mode
我在三个不同的文件夹中有一个名为 "ABCD.xlsm" 的 Excel 文件。
当我使用 VBScript 依次打开这些文件时,我无法 运行 宏和插件。
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile("D:\Temp\Excellocation.txt", 1, False)
Do While theFile.AtEndOfStream <> True
retstring = retstring & theFile.ReadLine
Loop
theFile.Close
lx_loc = retstring
fso.DeleteFile "D:\Temp\Excellocation.txt"
set objExcel = Createobject("Excel.Application")
objExcel.visible = True
objExcel.workbooks.open(lx_loc)
msgBox "RUN macro CallVSTOMethod and press ok",1, true
在代码中,文本文件具有 Excel 文件的位置。
如果只有一次使用此代码,那么我没有问题。当我多次调用此函数时,我无法 运行 加载项或宏。
这是因为当你用连接打开你的文件时,它锁定了这个文件,所以你无法打开它。您可以做的是复制过去的副本并打开副本。它会立即打开! ;)
我在三个不同的文件夹中有一个名为 "ABCD.xlsm" 的 Excel 文件。
当我使用 VBScript 依次打开这些文件时,我无法 运行 宏和插件。
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile("D:\Temp\Excellocation.txt", 1, False)
Do While theFile.AtEndOfStream <> True
retstring = retstring & theFile.ReadLine
Loop
theFile.Close
lx_loc = retstring
fso.DeleteFile "D:\Temp\Excellocation.txt"
set objExcel = Createobject("Excel.Application")
objExcel.visible = True
objExcel.workbooks.open(lx_loc)
msgBox "RUN macro CallVSTOMethod and press ok",1, true
在代码中,文本文件具有 Excel 文件的位置。
如果只有一次使用此代码,那么我没有问题。当我多次调用此函数时,我无法 运行 加载项或宏。
这是因为当你用连接打开你的文件时,它锁定了这个文件,所以你无法打开它。您可以做的是复制过去的副本并打开副本。它会立即打开! ;)