954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ms word mailto hyperlink

Sorry, maybe I post this in the wrong section.
But, I hope it is simple enough to be answered :)

I have .dot ms word template with mailto hyperlink.
something like: neosonic@neosonic.com, link to mailto: [email]neosonic@neosonic.com[/email]

I have tried to edit it manually in the .dot file, and that mailto is automatically changes when I change the email address, that's what I need.

And then I replaced that hyperlink as #email# then used replacetags function in for my vb6 program to replace it with an email for the database. But, the problem came up. Those mailto hyperlink doesn't change automatically anymore... which cause
fromdatabase@fromdatabase.com still links to [email]neosonic@neosonic.com[/email].

What can I do to somehow change that hyperlink automatically? Is there any way to do it? thanks.

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

Neo, I'm not sure what you need here. Please explain this in a more simple way, thanks.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Sorry mate, I will try to reword it, hopefully it will be clear.

I'm using ms word template .dot file to create an automated letter to each person in the database.

There is a hyperlink in it. So the receptionist just needs to click on it and it will be directed to her outlook to send the letter to the particular email that is written in that hyperlink.

My problem is, I tried rename that email address with my vb6 program.
while that hyperlink can be renamed, it is still linked into the default email address, instead of the renamed email.

If I rename that hyperlink manually in ms word by typing it, the hyperlink is automatically updated as I write the new email address.

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

The reason is when you change it in vb6, the word doc is already static from the previous call. You need to unload the .dot, change the email address and reload the .dot again. It will then contain the new address.

It works similar to a web page, once loaded, it becomes static. Have a look at these Daniweb pages for instance. If you do not refresh the page (reload it) it will still show the same information as when you opened it.:)

Makes sense?

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

it makes sense :) thanks for the insight :)

I have found the reload method in

http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.reload(v=vs.80).aspx#Y87

and I use W.activeDocument.Reload , but it said that command failed.
(W is the ms word object, I used Set W = CreateObject("word.application") on the initialization of the class).

Do you have any clue about it?

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

I +would rather close the entire document in code as you would have after the user is done with it. Then load it again in code as you did in the first instance when it was opened. The time difference in closing and reloading is minimal, the user would hardly notice the reloading.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

that's a good trick :)
It didn't work for me though..

I saved it as a .doc document, then I closed it with W.Quit, then I created a new word object and open the saved .doc document.

But the hyperlink stays wrong :(

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

Neo, paste me all the code you have where the email gets changed, the document gets loaded, the mail gets changed. I'll have to work through all the code to see where your problem lies.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Here is my code mate, sorry for bothering you a lot.

'initialize word:

Set W = CreateObject("word.application")

'open it

W.Documents.Add app.path & "\mydoc.dot", 0

'show it

W.WordBasic.appshow

'replace tags

W.ActiveWindow.Selection.Find.Execute "#Email#", 0, 0, 0, 0, 0, 1, 1, 0, "destinationemail@hotmail.com", 2

'save it

W.ActiveDocument.SaveAs app.path & "\mydoc.doc", FileFormat:=wdOpenFormatAuto, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False

'close it

W.ActiveDocument.Close

'open it again

Set W = CreateObject("word.application")

W.Documents.Add app.path & "\mydoc.doc", 0

W.WordBasic.appshow
neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

No problem. I'll post a solution a bit later, meetings and stuff AND I'm watching the cricket.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

oo cool, you're into cricket too :) sorry for bothering you mate, enjoy :)

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

Of course. Almost done with your testing.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

I really really appreciate your help mate. I don't even know what can I do for you in return

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

Have a look at this. This is however saving the changes in a text file, word will raise errors.

Private Sub Command2_Click()

Dim alltxt As String
  Dim nbytes As Long

  Open App.Path & "\mydoc.txt" For Binary As #1
  nbytes = LOF(1)
  alltxt = Space$(nbytes)
  Get #1, 1, alltxt
  Close #1

  alltxt = "Andre@there.com"

  Open App.Path & "\mydoc.txt" For Binary As #1
  Put #1, 1, alltxt
  Close #1
End Sub
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

ok mate, I'll try it as soon as possible :) thanks a lot

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

Pleasure. Let me know.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Yes, it works :)
But, sorry mate, I didn't get your point by giving me this example :(
Please enlighten me a little bit.. :p

It put the email address into the txt file.. but how does it relate to replacing the link in the hyperlink? Sorry mate, maybe I'm not as sharp as you think :p

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

Now I don't understand what you mean. Is this not what you were looking for, as per your previous code?

You want to change the email address from the one currently in the text file with the new one you have just created. Thats what I understand from all of this.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

oops.. sorry mate, no that is not exactly what I want. tomorrow, I will send you a folder with everything in it and you can run that project.
Or maybe, you have helped me a way too much in here.. I will just go away and solve it (or leave it unsolved). In both cases, I'll send the folder to you tomorrow. thanks a lot :)

neosonic
Junior Poster
137 posts since Nov 2009
Reputation Points: 22
Solved Threads: 1
 

No problem. Send the folder. We are here to solve other posters problems, so you will never become a nuisance.:)

The main thing is that we must find a solution. You have showed a lot of effort from your side, hence all the help from me. PM me once you have posted the folder.;)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: