Help Please - Changing fixed path to relative in Macro VBA Code

creativespaace

New Member
Joined
Oct 25, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
All Experts,

If someone could help please as I am looking to change fixed path to relative path in following code

Below Macro code is in word document and this is linked to excel file to get data in the same folder. I usually copy entire folder to new location and looking for a code where it will pick excel file from same folder (08.Documents) where word and excel files are.

Name of all files folders are kept same and only thing changes is folder name as shown below in red.

Appreciate if someone could guide with some magic. Thank You

Current code for reference.

Sub test2()
'
' test2 Macro
'
'
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Users\Sheladiya\OneDrive - Sheladiya Limited\2.Sheladiya\04a.PWLive\000.Blank Project - Copy\08.Documents\PWMailMerge.xlsx" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\04a.PWLive\000.Blank Project - Copy\08.Documents\PWMailMerge.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System data" _
, SQLStatement:="SELECT * FROM `PWData$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
All Experts,

If someone could help please as I am looking to change fixed path to relative path in following code

Below Macro code is in word document and this is linked to excel file to get data in the same folder. I usually copy entire folder to new location and looking for a code where it will pick excel file from same folder (08.Documents) where word and excel files are.

Name of all files folders are kept same and only thing changes is folder name as shown below in red.

Appreciate if someone could guide with some magic. Thank You

Current code for reference.

Sub test2()
'
' test2 Macro
'
'
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Users\04a.PWLive\000.Blank Project - Copy\08.Documents\PWMailMerge.xlsx" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Users\04a.PWLive\000.Blank Project - Copy\08.Documents\PWMailMerge.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System data" _
, SQLStatement:="SELECT * FROM `PWData$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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