簡體   English   中英

在讀寫模式下使用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文件的位置。

如果此代碼只有一種用法,那么我沒有問題。 當我多次調用此函數時,無法運行插件或宏。

這是因為當您通過連接打開文件時,它正在鎖定此文件,因此您無法打開它。 您可以做的就是復制副本,然后打開副本。 它將立即打開! ;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM