Get Data from workbook with dynamic name

seldem

New Member
Joined
Dec 25, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to create a dashboard worksheet collecting data from 2 types of closed workbooks:
1. Getting data from constant name which is not changing. Since the range is always same, It is easy, I can get to the selected cell on the dashboard worksheet with a linked formula connected to data workbook
2. Getting data from a workbook with dynamic name changing based on the date (such as 'C:\Documents\Report 23 12 2021.xlsx' or 'C:\Documents\Report 24 12 2021.xlsx' etc. The cell address is always same on these workbooks. Let's say A2:A2. But the file names are changing with "Report DD MM YYYY" format. I think for this process I have use VBA.

Could you help me on 2nd option which is getting data from workbook changing named dynamicly.

Best Regards,

Selim Demirpençe
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Welcome to the Board!

Don't know if you are still looking for an answer, but how about something like this?
VBA Code:
Sub BuildReference()
    
    Dim dte As String

'   Get current date in DD MM YYYY format
    dte = Format(Date, "dd mm yyyy")

'   Place direct reference in cell A2
    Range("A2").Formula = "'C:\Documents\Report " & dte & ".xlsx]Sheet1'!$A$2"
    
End Sub
 
Upvote 0
Welcome to the Board!

Don't know if you are still looking for an answer, but how about something like this?
VBA Code:
Sub BuildReference()
   
    Dim dte As String

'   Get current date in DD MM YYYY format
    dte = Format(Date, "dd mm yyyy")

'   Place direct reference in cell A2
    Range("A2").Formula = "'C:\Documents\Report " & dte & ".xlsx]Sheet1'!$A$2"
   
End Sub
Hello Joe,
Sorry for my late reply. Thanks for your suggestion. I will try and let you know.

Best Regards,

Selim
 
Upvote 0
Dear Joe,
I've tried your suggestion and it worked -with a little touch-. I add a '=' before direct reference in cell A2. Otherwise it gives just the address of the reference.
The is the final version of the code. I put here in order to help somebody who may need for a similar case. (I marked in bold red the little corrections)

VBA Code:
Sub BuildReference()

Dim dte As String

' Get current date in DD MM YYYY format
dte = Format(Date, "dd mm yyyy")

' Place direct reference in cell A2
Range("A2").Formula = "
='C:\Documents\[Report " & dte & ".xlsx]Sheet1'!$A$2"

End Sub



Thanks Again,

Best Regards,

Selim
 
Upvote 0
Sorry about the typo, and forgetting the equals sign.
And yes, if the file name contains spaces, it will need to be enclosed in square brackets.

Glad you got it working.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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