运行以下代码行时,出现Expected:=
的编译错误:
MiscFunctions.AutoOpenRequiredWorkbook (myFileNameToOpen, myFilePath)
这是返回错误的函数的代码:
Function AutoOpenRequiredWorkbook(myFileNameToOpen As String, myFilePath As String) As String
Dim OpenedOk, FileToOpen As String
OpenedOk = "NOT Opened"
If UserName = "scorekeeper" Then GoTo NothingElseTodoForscorekeeper: ' NothingElseTodoForscorekeeper
'TempPath = Environ("userprofile")
FileToOpen = [myFilePath] & myFileNameToOpen '' FileToOpen = TempPath & "\OneDrive\MasterFiles\" & FileNameToOpen
'Stop ' just for debugging
If IsFileOpen(myFileNameToOpen) Then
OpenedOk = "OpenedOk"
GoTo AlreadyOpen
Else
Workbooks.Open filename:=myFileNameToOpen, UpdateLinks:=0
Windows(myFileNameToOpen).Visible = False ' hide this workbook
OpenedOk = "OpenedOk"
End If
NothingElseTodoForscorekeeper:
AlreadyOpen:
AutoOpenRequiredWookbook = OpenedOk
'This example names window one in the active workbook Consolidated Balance Sheet. _
'This name is then used as the index to the Windows collection.
'ActiveWorkbook.Windows(1).Caption = "Consolidated Balance Sheet"
'ActiveWorkbook.Windows("Consolidated Balance Sheet").ActiveSheet.Calculate
End Function
答案 0 :(得分:1)
使用以下内容:
MiscFunctions.AutoOpenRequiredWorkbook myFileNameToOpen, myFilePath
要在函数的参数周围使用括号的情况是,当您将函数返回的值分配给变量时。即:
x = MiscFunctions.AutoOpenRequiredWorkbook(myFileNameToOpen, myFilePath)
也可以。
答案 1 :(得分:0)
感谢DecimalTurn,因为我包括了添加byref部分,从而解决了它。 函数AutoOpenRequiredWorkbook(ByVal myFileNameToOpen作为字符串,ByVal myFilePath作为字符串)作为字符串 非常感谢您的宝贵时间。我希望我有一天能回报您的好意。