creativespaace
New Member
- Joined
- Oct 25, 2022
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hello All,
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
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