VBA code to grab a file path from an Excel cell

fwk

New Member
Joined
Jan 9, 2024
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have a workbook that downloads data from SAP. This workbook is developed to be a tool for different users across different sites. What i am trying to achieve is to develop VBA code that refence a spesific cell on a sheet where the different users can copy in the file path of where they store the data.

The current working code has this:-

' Open the IW39 Dwnld workbook
Workbooks.Open ("C:\Users\10005500\OneDrive\Desktop\SAP Automated data extract\Material Report\SAP Downloads\IW39 Dwnld.xlsx")
Sheets("Sheet1").Select
Range("A1").Select

I need the VBA to reference the cell in the sheet below (A2) where this path is stored. Below is a snippet of the sheet where users input their criteria. Each site would hence have different criteria and it would be better managed to input on the sheet instead of manipulating the VBA code for each.

1704786400153.png


I am a beginner in VBA and any assistance and detailed explanation how this can be achieved would be appreciated.
FWK
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Concatenate the cells and declare that as a variable, then use that in your open statement.
 
Upvote 0
Concatenate the cells and declare that as a variable, then use that in your open statement.

Where my cells were A1 for Path and A2 for Filename

VBA Code:
Sub myOpenWorkbook()

WorkbookToOpen = Range("A1").Value & "\" & Range("A2").Value & ".xlsx"

Workbooks.Open (WorkbookToOpen)

End Sub
 
Upvote 0
Concatenate the cells and declare that as a variable, then use that in your open statement.

Where my cells were A1 for Path and A2 for Filename

VBA Code:
Sub myOpenWorkbook()

WorkbookToOpen = Range("A1").Value & "\" & Range("A2").Value & ".xlsx"

Workbooks.Open (WorkbookToOpen)

End Sub
Thankyou very much, I will test it.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top