PotatoPotatis
New Member
- Joined
- Mar 9, 2023
- Messages
- 4
- Office Version
- 2019
- Platform
- Windows
Hi. I have a formula that takes user inputs and generates a file and range path in cell A1. So instead of hard coding the path I want it to use the text path in cell A1 dynamically to know what cells to copy. A1 is currently:
'C:\Users\DTAK\Desktop\Processing Tool\[Outlet 2012.xlsx]Sheet1'!A30:E44
The following code works hardcoded, but I don’t know how to adjust it. Any help is much appreciated!
I tried this but it failed with a 400 error:
I’d also prefer this works without any source files opening to the user. I’m fine with it running in the background though, of course.
Thank you.
'C:\Users\DTAK\Desktop\Processing Tool\[Outlet 2012.xlsx]Sheet1'!A30:E44
The following code works hardcoded, but I don’t know how to adjust it. Any help is much appreciated!
VBA Code:
Sub GetDataFromClosedBook()
Dim mydata As String
'data location & range to copy
mydata = "='C:\Users\DTAK\Desktop\Processing Tool\[Outlet 2012.xlsx]Sheet1'!A30:E44" '<< change as required
'link to worksheet
With ThisWorkbook.Worksheets(3).Range("A30:E44") '<< change as required
.Formula = mydata
'convert formula to text
.Value = .Value
End With
End Sub
I tried this but it failed with a 400 error:
VBA Code:
Sub GetDataFromClosedBook()
Dim mydata As String
'data location & range to copy
mydata = "='" & Range("A1").Value & "'" '<< change as required
'link to worksheet
With ThisWorkbook.Worksheets(3).Range("A30:E44") '<< change as required
.Formula = mydata
'convert formula to text
.Value = .Value
End With
End Sub
I’d also prefer this works without any source files opening to the user. I’m fine with it running in the background though, of course.
Thank you.