Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
SHKDXB SHKDXB is offline
external usenet poster
 
Posts: 2
Default Ralative path for data source

hi anybody can help me to make the path of the data source as relative?. when
trnasporting the files to other machines, i have problem of missisng data
soure - due to absoulte path in the main mail merge documnet. is there a way
to change this data source to relative path??
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Ralative path for data source

is there a way
to change this data source to relative path??


Not easily - you have to use code, e.g. Word VBA.

First, before you distribute the solution, ensure that the Mail Merge Main
Document has been disconnected from its data source. You have to do that
because nothing you do in VBA can change the data source path /before/ Word
tries to open it.

You can disconnect the data source while the mail merge main document is
open by using

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

in the Word VBA Editor Immediate WIndow.

Then, in Word VBA, create an ordinary module in your Document and put a
routine such as the following in it - this assumes that you know the name of
the .xls and that it will be in the same folder as the .doc

Sub AutoOpen()
Dim strDataSource As String
Dim strConnection As String
Dim strQuery As String

' set this to be the file name of your data source
strDataSource = "myexcelfile.xls"

' set this to be the connection string for your data source
'strConnection = ""

' set this to be the query for your data source
' if you need to sort aor filter, you need to add
' the appropriate ORDER BY and WHERE clauses
' strQuery = "SELECT * FROM [myrangename]"

With ActiveDocument
strDataSource = .Path & "\" & strDataSource
With .MailMerge
.OpenDataSource _
Name:=strDataSource, _
SQLStatement:=str
' use the type you need
.MainDocumentType = wdFormLetters
' use the destination you need
.Destination = wdSendToNewDocument

' NB the above code does not execute the merge.
End With
End With
End Sub

Unfortunately, you, or your user, will probably also have to take account of
the following artiicle:

http://support.microsoft.com/kb/825765/en-us

--
Peter Jamieson
http://tips.pjmsn.me.uk

"SHKDXB" wrote in message
...
hi anybody can help me to make the path of the data source as relative?.
when
trnasporting the files to other machines, i have problem of missisng data
soure - due to absoulte path in the main mail merge documnet. is there a
way
to change this data source to relative path??


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
SHKDXB SHKDXB is offline
external usenet poster
 
Posts: 2
Default Ralative path for data source

Thanks for the info
couldn't understsnad the line

' set this to be the connection string for your data source
'strConnection = ""

tried but getting error as "compile error argument not optional" str
highlighted in statemnet SQLStatement:=Str
any help?


"Peter Jamieson" wrote:

is there a way
to change this data source to relative path??


Not easily - you have to use code, e.g. Word VBA.

First, before you distribute the solution, ensure that the Mail Merge Main
Document has been disconnected from its data source. You have to do that
because nothing you do in VBA can change the data source path /before/ Word
tries to open it.

You can disconnect the data source while the mail merge main document is
open by using

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

in the Word VBA Editor Immediate WIndow.

Then, in Word VBA, create an ordinary module in your Document and put a
routine such as the following in it - this assumes that you know the name of
the .xls and that it will be in the same folder as the .doc

Sub AutoOpen()
Dim strDataSource As String
Dim strConnection As String
Dim strQuery As String

' set this to be the file name of your data source
strDataSource = "myexcelfile.xls"

' set this to be the connection string for your data source
'strConnection = ""

' set this to be the query for your data source
' if you need to sort aor filter, you need to add
' the appropriate ORDER BY and WHERE clauses
' strQuery = "SELECT * FROM [myrangename]"

With ActiveDocument
strDataSource = .Path & "\" & strDataSource
With .MailMerge
.OpenDataSource _
Name:=strDataSource, _
SQLStatement:=str
' use the type you need
.MainDocumentType = wdFormLetters
' use the destination you need
.Destination = wdSendToNewDocument

' NB the above code does not execute the merge.
End With
End With
End Sub

Unfortunately, you, or your user, will probably also have to take account of
the following artiicle:

http://support.microsoft.com/kb/825765/en-us

--
Peter Jamieson
http://tips.pjmsn.me.uk

"SHKDXB" wrote in message
...
hi anybody can help me to make the path of the data source as relative?.
when
trnasporting the files to other machines, i have problem of missisng data
soure - due to absoulte path in the main mail merge documnet. is there a
way
to change this data source to relative path??



  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Ralative path for data source

Yes, there are some errors in the code. What you need depends partly on the
data source, but...

' set this to be the connection string for your data source
strConnection = ""

' set this to be the query for your data source
' if you need to sort or filter, you need to add
' the appropriate ORDER BY and WHERE clauses
strQuery = "SELECT * FROM [myrangename]"

With ActiveDocument
strDataSource = .Path & "\" & strDataSource
With .MailMerge
.OpenDataSource _
Name:=strDataSource, _
Connection:=strConnection, _
SQLStatement:=strQuery

and so on...


--
Peter Jamieson
http://tips.pjmsn.me.uk

"SHKDXB" wrote in message
...
Thanks for the info
couldn't understsnad the line

' set this to be the connection string for your data source
'strConnection = ""

tried but getting error as "compile error argument not optional" str
highlighted in statemnet SQLStatement:=Str
any help?


"Peter Jamieson" wrote:

is there a way
to change this data source to relative path??


Not easily - you have to use code, e.g. Word VBA.

First, before you distribute the solution, ensure that the Mail Merge
Main
Document has been disconnected from its data source. You have to do that
because nothing you do in VBA can change the data source path /before/
Word
tries to open it.

You can disconnect the data source while the mail merge main document is
open by using

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

in the Word VBA Editor Immediate WIndow.

Then, in Word VBA, create an ordinary module in your Document and put a
routine such as the following in it - this assumes that you know the name
of
the .xls and that it will be in the same folder as the .doc

Sub AutoOpen()
Dim strDataSource As String
Dim strConnection As String
Dim strQuery As String

' set this to be the file name of your data source
strDataSource = "myexcelfile.xls"

' set this to be the connection string for your data source
'strConnection = ""

' set this to be the query for your data source
' if you need to sort aor filter, you need to add
' the appropriate ORDER BY and WHERE clauses
' strQuery = "SELECT * FROM [myrangename]"

With ActiveDocument
strDataSource = .Path & "\" & strDataSource
With .MailMerge
.OpenDataSource _
Name:=strDataSource, _
SQLStatement:=str
' use the type you need
.MainDocumentType = wdFormLetters
' use the destination you need
.Destination = wdSendToNewDocument

' NB the above code does not execute the merge.
End With
End With
End Sub

Unfortunately, you, or your user, will probably also have to take account
of
the following artiicle:

http://support.microsoft.com/kb/825765/en-us

--
Peter Jamieson
http://tips.pjmsn.me.uk

"SHKDXB" wrote in message
...
hi anybody can help me to make the path of the data source as
relative?.
when
trnasporting the files to other machines, i have problem of missisng
data
soure - due to absoulte path in the main mail merge documnet. is there
a
way
to change this data source to relative path??




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically setting the path to the data source Andrew Duncan Mailmerge 6 October 4th 06 01:48 PM
How to link a different Mailmerge header source and data source? Eleni_Malli Mailmerge 1 May 3rd 06 02:08 PM
Path to data Source JethroUK© Mailmerge 3 November 18th 05 07:52 AM
Includetext Source Path Office 2003 Steve Microsoft Word Help 5 April 12th 05 01:26 PM
Merge Data Source path Peter Jamieson Mailmerge 0 November 25th 04 08:15 PM


All times are GMT +1. The time now is 12:42 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"