Open workbook using following code [Closed]

 x -
Private Sub CommandButton1_Click()
Sheets("Site Name").Select
S = Range("A1:A2")
D = Range("B1:B2")
E = Range("B2")
Location = Range("C1")

Workbooks. Open(" & Location & "\" & S & ".xlsx")
  • Please give a solution about code, in my VBA syntax error is showing

Workbooks. Open(" & Location & "\" & S & ".xlsx") this line.*

1 reply


Use these lines instead:

S = Range("A1")
file_to_open = Location & "\" & S & ".xlsx"
Workbooks.Open (file_to_open)

Using the variable 'file_to_open' you can step through and see what value is being assigned to it more easily when debugging.

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!