WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Ralative path for data source

 
   Home -> Office -> MailMerge Fields RSS
Next:  creating categories for a word mail merge  
Author Message
SHKDXB

External


Since: Nov 25, 2007
Posts: 2



(Msg. 1) Posted: Sun Nov 25, 2007 7:25 pm
Post subject: Ralative path for data source
Archived from groups: microsoft>public>word>mailmerge>fields (more info?)

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??
Back to top
Login to vote
Peter Jamieson

External


Since: Aug 10, 2004
Posts: 2200



(Msg. 2) Posted: Mon Nov 26, 2007 10:02 am
Post subject: Re: Ralative path for data source [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> 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??
Back to top
Login to vote
SHKDXB

External


Since: Nov 25, 2007
Posts: 2



(Msg. 3) Posted: Mon Nov 26, 2007 6:54 pm
Post subject: Re: Ralative path for data source [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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??
>
>
Back to top
Login to vote
Peter Jamieson

External


Since: Aug 10, 2004
Posts: 2200



(Msg. 4) Posted: Tue Nov 27, 2007 9:17 am
Post subject: Re: Ralative path for data source [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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??
>>
>>
Back to top
Login to vote
alexander taylor

External


Since: Aug 07, 2011
Posts: 1



(Msg. 5) Posted: Sun Aug 07, 2011 8:05 pm
Post subject: Re: Ralative path for data source [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

you don't need to use any macros to use a relative path to a mail merge data source word documents created in word 2007 and later.

see this article i wrote to answer your question:
http://devblog.alexsapps.com/2011/08/how-to-use-relative-path-to-data-...rce.htm

> On Sunday, November 25, 2007 10:25 PM SHKDX wrote:

> 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??


>> On Monday, November 26, 2007 5:02 AM Peter Jamieson wrote:

>> 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
>>


>>> On Monday, November 26, 2007 9:54 PM SHKDX wrote:

>>> 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:


>>>> On Tuesday, November 27, 2007 4:17 AM Peter Jamieson wrote:

>>>> 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
>>>> news:B482BD76-5E2F-44E1-98D0-5B2E539F3714@microsoft.com...
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> MailMerge Fields All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security

  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Help Forum Terms of Service |
  • Link to WUGNET |
  • IT Support