Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / December 2003

Tip: Looking for answers? Try searching our database.

Mail Merge - Cannot get URL to Merge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick Giacobe - 11 Nov 2003 05:24 GMT
I am using Excel 2002 SP2 for the data source, and Word
2002 SP2 to merge into a document.

I am trying to get a URL to merge into the merged file.  
However, when it does so - I get the text of the URL, but
no hyperlink underlining - all I get is the text.

I've tried the ALT-F9 trick to show the codes - and tried
to insert a merge field code into the URL line - but no
luck.

This can't be all that hard - anyone have any ideas?

TIA

-- Nick
Peter Jamieson - 11 Nov 2003 17:50 GMT
Here's something I posted a while back in response to a similar question...

You /may/ be able to get what you want using fields, and someone may come
along and suggest how to do that. But I think you will need to use VBA and
the mailmerge events.If you're familiar with VBA, I suggest you try the
following experiment. If you're familiar with Events, you can probably skip
some of this stuff.

The overview is as follows:
a. In your mail merge main document, you will have a bookmark named "mybm"
that specifies where you want the hyperlink to go
b. also in the document, you have a class module with a routine that
responds to the Mailmerge "Before Record Merge" event. This routine will
insert a hyperlink at the specified point, using data from the current
record in the data source
c. Also in the document, you have a module with an AutoOpen routine that
creates an instance of your class and initialises event handling.

I'm not a VBA expert so please don't regard the following code as
"polished" - you may need to add error handling and so on before it will all
work reliably for you or your users.

So...

1. Create a new document, connect it to your data source, and insert one
merge field and a bookmark named "mybm"

2. Open up the VBA Editor and
a. insert a class module.
b. name it EventClassModule in the properties box
c. Copy the following code into the module:

Public WithEvents App As Word.Application

Private Sub App_MailMergeBeforeRecordMerge(BYVal Doc As Document, Cancel As
Boolean)
Dim dt as String
Dim lt as String
Dim h as Hyperlink
Dim r as Range

' set the range variable to our placeholder bookmark
Set r = Doc.Bookmarks("mybm").Range

' delete any existing text (this is needed for records after record 1)
r.Text = ""

' construct the link text that you want. I'm assuming your data source has
fields called idfield and namefield
lt = http://www.testsite.com?id= & _
Doc.MailMerge.DataSource.DataFields("idfield") & _
"&name=" & _
Doc.MailMerge.DataSource.DataFields("namefield")
' set up the display text that you want. If it should be the same as the
link text, do that:
dt = lt

' insert the hyperlink you want
Set h = Doc.Hyperlinks.Add(Anchor:=r, Address=lt, TextToDisplay:=dt)

' Set mybm to "cover" the inserted link so it is easy to delete the old
hyperlink

Doc.Bookmarks.Add Name:="mybm", Range:=h.Range

Set r = Nothing
Set h = Nothing

End Sub

3. Insert an ordinary module (the name does not matter) and insert the
following code:

Dim x As New EventClassModule

Sub autoopen()
Set x.App = Word.Application
End Sub

4. Save and close the document. Open it to trigger the autoopen, then
perform a test merge.

NB, if you start changing the code you may find that you need to re-run your
autoopen code again, and/or save/close/open the document.

--
Peter Jamieson
MS Word MVP

> I am using Excel 2002 SP2 for the data source, and Word
> 2002 SP2 to merge into a document.
[quoted text clipped - 12 lines]
>
> -- Nick
Nick Giacobe - 12 Nov 2003 02:47 GMT
That did the trick... of course, I had to merge the split
lines back together... and modify the code to meet my
variables/URL format, etc.  There was one typo in your
code example -

Set h = Doc.Hyperlinks.Add(Anchor:=r, Address=lt,
textToDisplay:=dt)

should be

Set h = Doc.Hyperlinks.Add(Anchor:=r, Address:=lt,
TextToDisplay:=dt)

Other than that, it worked like a charm.  I see that the
example you used assumes a base URL, then some variables
in the query (after the ?)... whereas all I'm trying to
do is import a full URL from the data source.  You would
THINK that something as simple as what I'm doing wouldn't
require that complicated of a solution.

I'm curious to see what's in the next version of Word...

Thanks again.

-- Nick

>-----Original Message-----
>Here's something I posted a while back in response to a similar question...
[quoted text clipped - 104 lines]
>
>.
Peter Jamieson - 12 Nov 2003 09:06 GMT
Hi Nick,

Glad it worked, and thanks for the feedback.

> You would
> THINK that something as simple as what I'm doing wouldn't
> require that complicated of a solution.

I agree.

--
Peter Jamieson
MS Word MVP

> That did the trick... of course, I had to merge the split
> lines back together... and modify the code to meet my
[quoted text clipped - 158 lines]
> >
> >.
Cindy M  -WordMVP- - 12 Nov 2003 17:18 GMT
Hi Nick (and all others with this problem who might think to
read this)

It took me a few days, but I believe I finally remember
what's going on here. This is a problem specific to Excel
data sources. Somehow, URL in an Excel cell comes across
into Word with some extra or missing character. I can't
recall the exact details.

But as a test, try exporting the Excel table to a delimited
text file. Or copy paste the table into a Word document. Now
use either (or both, if you care to test both) as a data
source in a test merge. Does the Hyperlink come across
correctly?

> I am using Excel 2002 SP2 for the data source, and Word
> 2002 SP2 to merge into a document.
>  
> I am trying to get a URL to merge into the merged file.  
> However, when it does so - I get the text of the URL, but
> no hyperlink underlining - all I get is the text.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)
Patty Day - 01 Dec 2003 18:19 GMT
Hi Nick,
Try select all, right click, and select update Hyperlink.

That may take care of your inactive hyperlinks.

patty

>-----Original Message-----
>I am using Excel 2002 SP2 for the data source, and Word
[quoted text clipped - 14 lines]
>-- Nick
>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.