Open workbook using following code

Closed
reza - Updated by reza on 10/03/17 at 12:24 PM
 x - Mar 10, 2017 at 03:51 PM
Private Sub CommandButton1_Click()
Workbooks("Patch.xlsm").Activate
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 response

reza,

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.
0