所以这就是我如何调用函数:
FilePathLoD(FirewallAssy)
功能是:
Function FilePathLoD(FileName as String)
Application.ScreenUpdating = False
Activewindow.WindowState = xlMinimized
FilePathLoD = "E:\List of Drawings"
Workbooks.Open (FilePathLoD & "\" & FileName & "LoD.xlsm")
Activewindow.WindowState = xlMaximized
ThisWorkbook.Activate
Application.ScreenUpdating = True
End Function
当我调用函数时,字符串会一起解析。
E:\图纸清单\ FalseLoD.xlsm
为什么会发生这种情况?如何解决这个问题?
答案 0 :(得分:0)
FileName 是Workbooks.Open method的第一个参数。将其更改为 fname 以避免混淆。
将此更改为 Sub 过程。你没有回报价值;简单地实现一个方法。对于此操作,Sub比Function更合适。
Sub FilePathLoD(fName as String)
Dim fPath as String
Application.ScreenUpdating = False
Activewindow.WindowState = xlMinimized
fPath = "E:\List of Drawings"
Workbooks.Open (fPath & "\" & fName & "LoD.xlsm")
Activewindow.WindowState = xlMaximized
ThisWorkbook.Activate
Application.ScreenUpdating = True
End Function
将其称为程序。
FilePathLoD FirewallAssy
'... or,
Call FilePathLoD(FirewallAssy)