Marlon Taylor
Marlon Taylor

Reputation: 23

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

I have tried this but I keep getting an error message of syntax but I am relatively new and struggle making the correction.

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

Upvotes: 2

Views: 33

Answers (2)

Ron Rosenfeld
Ron Rosenfeld

Reputation: 60364

The underscores are causing the problem. They are line continuation characters in the VBE and somehow, in your writing or copy/pasting the code line, you have messed up the syntax.

The underscore should be preceded by a space and followed by newline.

So proper syntax of that line would be:

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

Upvotes: 1

Pᴇʜ
Pᴇʜ

Reputation: 57743

This would be the correct syntax to concatenate strings:

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

Upvotes: 0

Related Questions