Use a wildcard in VBA to allow users on a shared google drive to auto link into Excel files

Sarkman22

New Member
Joined
Aug 8, 2014
Messages
25
Upfront, I apologize for my rookie skills in VBA- I am a point and click Macro creator so VBA is new to me. However, I feel I am trying to do something simple and could use some help....

I am trying to create a Macro in Excel (and Access later), to automatically link into an Excel file that is on a shared Google drive. However, when my co worker tries to run the macro, the file path changes because he is on his computer. How do I write the file path to use a * or wildcard to still find the file if the root folder changes?

E.g.

I write the macro referencing a file:
C:\Users\JSmith\Google Drive\Tables\SubTables\Table1.xlsx

My coworker tries to run the macro but it breaks because his file path is:
C:\Users\AWard\Google Drive\Tables\SubTables\Table1.xlsx

I tried:
C:\Users\*\Google Drive\Tables\SubTables\Table1.xlsx

But it didn't work.

Thank you very much for any help.

Andy
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Upfront, I apologize for my rookie skills in VBA- I am a point and click Macro creator so VBA is new to me. However, I feel I am trying to do something simple and could use some help....

I am trying to create a Macro in Excel (and Access later), to automatically link into an Excel file that is on a shared Google drive. However, when my co worker tries to run the macro, the file path changes because he is on his computer. How do I write the file path to use a * or wildcard to still find the file if the root folder changes?

E.g.

I write the macro referencing a file:
C:\Users\JSmith\Google Drive\Tables\SubTables\Table1.xlsx

My coworker tries to run the macro but it breaks because his file path is:
C:\Users\AWard\Google Drive\Tables\SubTables\Table1.xlsx

I tried:
C:\Users\*\Google Drive\Tables\SubTables\Table1.xlsx

But it didn't work.

Thank you very much for any help.

Andy


This should work (the Environ function returns the Windows username):

Code:
sPath = "C:\Users\" & Environ$("UserName") & "\Google Drive\Tables\SubTables\Table1.xlsx"
 
Upvote 0
This worked perfectly, and is a humongous help! Thank you very, very much.... I hope you don't mind a quick follow up question...

Can I do the same thing in Access? I want to have a "linked Excel file" (a linked table) referring to an Excel file on a shared Google drive where someone else can open the Access database and run queries/macros that I setup and have the link to the Excel table update for their user name.
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,292
Members
449,149
Latest member
mwdbActuary

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