我有一个 excel 文件目录,这些文件通过主文件中的 VBA 代码相互交互。
我以前从来没有遇到过这个问题,但是在复制整个目录以对副本进行一些开发工作(在不同的位置保持原件完好无损)之后,我在引用时遇到了“下标超出范围”的问题工作簿。
例如,之前使用这行代码一切正常(实际代码中没有任何更改):
现在抛出错误的代码(从未使用过):
ScheduleLocation = Workbooks("Master Schedule").Path
Run Code Online (Sandbox Code Playgroud)
但是,此行现在会引发错误。如果我用“Master Schedule.xlsm”替换“Master Schedule”,一切都会恢复正常。我以前遇到过这个问题,但我一直无法找出问题的根本原因。
不会抛出错误的代码:
ScheduleLocation = Workbooks("Master Schedule.xlsm").Path
Run Code Online (Sandbox Code Playgroud)
因此我的问题是:这是为什么?为什么名称(不带扩展名)有时不够用,有时又不合适?
我运行的模拟具有以下基本结构:
from time import time
def CSV(*args):
#write * args to .CSV file
return
def timeleft(a,L,period):
print(#details on how long last period took, ETA#)
for L in range(0,6,4):
for a in range(1,100):
timeA = time()
for t in range(1,1000):
## Manufacturer in Supply Chain ##
inventory_accounting_lists.append(#simple calculations#)
# Simulation to determine the optimal B-value (Basestock level)
for B in range(1,100):
for tau in range(1,1000):
## simple inventory accounting operations##
## Distributor in Supply Chain ##
inventory_accounting_lists.append(#simple calculations#)
# Simulation to …Run Code Online (Sandbox Code Playgroud)