VBA - Changing Power Query Source

Luca Tramontana 81 Reputation points
2025-11-14T09:05:27.5+00:00

Dear All,

I have a Power Query internal to an excel file.

I need your help on VBA programmatically change the below source value from C:\SERVICE\Service\List\January 2025.xlsm to C:\SERVICE\Service\List\November 2025.xlsm

User's image

Any idea?
Thanks for your help

Microsoft 365 and Office | Excel | Other | Windows
0 comments No comments
{count} votes

Answer accepted by question author
  1. riny 20,525 Reputation points Volunteer Moderator
    2025-11-14T17:04:42.99+00:00

    I suspect you did not connect PQ to the named range and then 'drilled down' to the file name and create a parameter. Therefore. PQ does not recognise "Filename".

    Have a look in the article in the link below. It describes the process in great detail.

    https://exceloffthegrid.com/power-query-source-cell-value/

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. riny 20,525 Reputation points Volunteer Moderator
    2025-11-14T14:17:21.5666667+00:00

    Why VBA? The correct way would be to use a parameter for the file name. Enter the name somewhere in your Excel workbook. Name it, for example "filename". Connect PQ to that named range.

    Drill down to get the filename as a text parameter. Use that in the Source step. So, rather than

    "C:\SERVICE\Service\List\January 2025.xlsm"

    it would then look like:

    "C:\SERVICE\Service\List" & filename

    0 comments No comments

  2. Luca Tramontana 81 Reputation points
    2025-11-14T15:48:47.8166667+00:00

    Thanks for your reply.

    Following your suggestion I have added into "Sheet1" cell E22 a named range: 'Filename'User's image

    Then, I have modified as below "C:\SERVICE BU\00 - Service BU\17 - Price List\Normal\2025\11" & Filename:image

    but I get the error:
    User's image

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.