Share via

Excel VBA - Getting Data source value

Anonymous
2023-06-14T21:40:13+00:00

Dear all,

I'm working on how to get the data source value below by VBA:

Image

which is C:\Users\mynane\Desktop\SourceData\New\Country-Iso_Codes_Table.xlsx

Any idea?

Thanks

Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2023-06-15T07:16:07+00:00

    AFAIK there is no way to get that path for sure.

    You can loop through the Workbook.Connections collection to get a WorkbookConnection and if you found a query you can access it using the Workbook.Queries collection to get each WorkbookQuery, but none of these objects has a property to get the related path.

    The reason is that a path can be dynamic, e.g. stored inside a parameter table, so you never know which file is used at runtime.

    Andreas.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2023-06-15T05:12:58+00:00

    Thanks for the feedback but my unknown value I need to detect is precisely this string value: C:\Users\mynane\Desktop\SourceData\New\Country-Iso_Codes_Table.xlsx

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-06-15T03:28:08+00:00

    try...

    Sub OpenWB()

    Dim wb1 As Workbook, wb2 As Workbook

    Set wb1 = ThisWorkbook

    Dim sPath

    sPath = "C:\Users\mynane\Desktop\SourceData\New\Country-Iso_Codes_Table.xlsx"

    Set wb2 = Workbooks.Open(sPath)

    End Sub

    Was this answer helpful?

    0 comments No comments