繁体   English   中英

有没有办法在excel vba 2010中连接文件路径?

[英]Is there a way to concontenate on a file path in excel vba 2010?

我已经尝试过这个,但我不断收到语法错误消息,但我相对较新并且很难进行更正。

Excel VBA 2010

Sub GoGetTimeSheet_Click()
    'Find Specific Employee Time Sheet Time Sheet
    Dim xWb As Workbook
    Dim wbName As String

    ''''This is where the highlight comes in''''''''


    Set xWb = Workbooks.Open("I:\Shared\Marlon\Production\Live Tracking\TimeSheetProtype\"&_TextBox1.Value_&".xlsm")

    ''''''...........'''''''''''..........''''''''''.........''''''


    wbName = xWb.Name
    If Err.Number <> 0 Then
        MsgBox "This workbook doesn't exist!", vbInformation, "Hallmark MFO"
        Err.Clear
    Else
        MsgBox "This workbook is opened!", vbInformation, "Congratulations, please proceed"

    End If

    Call cmdClose_Click
End Sub

下划线导致了问题。 它们是 VBE 中的行继续符,不知何故,在您编写或复制/粘贴代码行时,您弄乱了语法。

下划线前面应该有一个空格,然后是换行符

所以该行的正确语法是:

Set xWb = Workbooks.Open("I:\Shared\Marlon\Production\Live Tracking\TimeSheetProtype\" & _
        TextBox1.Value _
        & ".xlsm")

这将是连接字符串的正确语法:

Set xWb = Workbooks.Open("I:\Shared\Marlon\Production\Live Tracking\TimeSheetProtype\" & TextBox1.Value & ".xlsm")

暂无
暂无

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

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