简体   繁体   English

Excel + VBA +编译错误AutoOpenRequiredWorkbook(myFileNameToOpen,myFilePath)无法弄清楚为什么我得到此错误

[英]excel + vba + compile error AutoOpenRequiredWorkbook (myFileNameToOpen, myFilePath) can't figure out why I'm getting this error

I'm getting compile error of Expected:= when I run the following line of code: 运行以下代码行时,出现了Expected:=编译错误:

MiscFunctions.AutoOpenRequiredWorkbook (myFileNameToOpen, myFilePath)

And here is the code for the function that is returning the error: 这是返回错误的函数的代码:

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

Use the following: 使用以下内容:

MiscFunctions.AutoOpenRequiredWorkbook myFileNameToOpen, myFilePath

The case where you want to use parenthesis around the argmuments of your function is when you are assigning the value that the function returns to a variable. 您想在函数的参数周围使用括号的情况是,当您将函数返回的值分配给变量时。 ie: 即:

x = MiscFunctions.AutoOpenRequiredWorkbook(myFileNameToOpen, myFilePath)

would work as well. 也会工作。

Thanks to DecimalTurn as I included add the byref portion and that solved it. 感谢DecimalTurn,因为我包括了添加byref部分,从而解决了它。 Function AutoOpenRequiredWorkbook(ByVal myFileNameToOpen As String, ByVal myFilePath As String) As String Thanks so much for your time. 函数AutoOpenRequiredWorkbook(ByVal myFileNameToOpen作为字符串,ByVal myFilePath作为字符串)作为字符串非常感谢您的时间。 I hope that I maybe able to one day return your kindness. 我希望我有一天能回报您的好意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM