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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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