ROM
asked on
Change datasource of MS Word document on load and on button VBA.
I need to set the datasource for a set of mail merge documents to deploy to users on and off the LAN and may have updates each month.
To save remoting and resetting up datasources etc... (and also guessing the location) I want to set the datasource location on load or via button.. probably both.
Will use a specifically named file in the downloads directory of the current user.
Please supply a routine that will change the datasource. Please put XYZ as the path and I will generate etc...
The experience is:
User opens the document... it does it then and then merges... AND .. can be done via button to do an update.
OK.. seems as though this is a starting point:
Any additional suggestions?
R
To save remoting and resetting up datasources etc... (and also guessing the location) I want to set the datasource location on load or via button.. probably both.
Will use a specifically named file in the downloads directory of the current user.
Please supply a routine that will change the datasource. Please put XYZ as the path and I will generate etc...
The experience is:
User opens the document... it does it then and then merges... AND .. can be done via button to do an update.
OK.. seems as though this is a starting point:
With ActiveDocument.MailMerge
.OpenDataSource Name:="c:\mydocs\contracts\MyCont_R.CSV"
.Execute
End With
And . Execute if you want to mail merge as part of the routineAny additional suggestions?
R
You may try placing the following code on the ThisDocument Module...
Private Sub Document_Open()
Dim strPath As String, strFileName As String
'Get the downloads folder path
strPath = Environ("UserProfile") & "\Downloads\"
'CSV file name
strFileName = "MyCont_R.CSV"
With ActiveDocument.MailMerge
.OpenDataSource Name:=strPath & strFileName
.Execute
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window
And . Execute if you want to mail merge as part of the routineAny advances?
R