VBA to use cell reference and open another workbook

jas1980

New Member
Joined
Oct 14, 2016
Messages
39
Office Version
  1. 2019
Platform
  1. Windows
I have the following code in a workbook and it works perfectly, it opens the corresponding csv file, updates information and closes the csv, I am trying to change the address from being written into the code to being retrieved from a cell reference.

Any advice is much appreciated.

Sub GetFile()

Workbooks.Open "C:\Users\jamie\AppData\Roaming\MetaQuotes\Terminal\06980EAAF7FCC460D7BD131105CC8618\MQL4\Files\BSA_Transactions\BSA_Transactions.csv", UpdateLinks:=1
ActiveWorkbook.Close SaveChanges:=True

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
In A1 put the value "C:\Users\jamie\AppData\Roaming\MetaQuotes\Terminal\06980EAAF7FCC460D7BD131105CC8618\MQL4\Files\BSA_Transactions\"
VBA Code:
dim str1 as string
str1=trim(ltrim(cells(1,"A").value))      '1 is rownumber A is the column, read address from A1
Workbooks.Open  str1 & "BSA_Transactions.csv", UpdateLinks:=1
if it serves the need mark it as a solution.
 
Upvote 0
Solution
What about
VBA Code:
  Workbooks.Open Filename:=Range("A1")
 
Upvote 0
In A1 put the value "C:\Users\jamie\AppData\Roaming\MetaQuotes\Terminal\06980EAAF7FCC460D7BD131105CC8618\MQL4\Files\BSA_Transactions\"
VBA Code:
dim str1 as string
str1=trim(ltrim(cells(1,"A").value))      '1 is rownumber A is the column, read address from A1
Workbooks.Open  str1 & "BSA_Transactions.csv", UpdateLinks:=1
if it serves the need mark it as a solution.
Thank you for this it works perfectly, I just removed "BSA_Transactions.csv" so it was all in the same cell

Sub GetFile()

Dim str1 As String
str1 = Trim(LTrim(Cells(2, "P").Value)) '2 is rownumber P is the column, read address from O3

Workbooks.Open str1, UpdateLinks:=1
ActiveWorkbook.Close SaveChanges:=True

End Sub
 
Upvote 0
Hi
in my code Range("A1") should hold the path an the file name
"C:\Users\jamie\AppData\Roaming\MetaQuotes\Terminal\06980EAAF7FCC460D7BD131105CC8618\MQL4\Files\BSA_Transactions\BSA_Transactions.csv"
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,456
Members
452,514
Latest member
cjkelly15

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