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: neosonic@neosonic.com

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 neosonic@neosonic.com.

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

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

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.

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?

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.

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

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.

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

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

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

Of course. Almost done with your testing.

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

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

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

Pleasure. Let me know.:)

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

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.

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

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.;)

sorry mate, how can I post the folder or .zip file in here?
Is it possible to do so?

thanks a lot. I am ready to send it to you, but I don't know how to send to you .. lol :p

Yes it is. First zip the file using winzip or any other zip app. At the bottom of the message box, click on "Use Advanced Editor." Now select - "Manage Attachments". Add the zip file from there. Just pay attention to the size of the file. Zip files can only be up to 10MB.

Ok mate, I have attached them in .zip file. thanks a lot

Ok, I saw what you meant. I'll post something a bit later...

thanks mate :)

This seems to be a bit more involved using a word document because you have to use the inner workings of MS Word to delete the hyperlink and then add the new and then save the entire document.

I'll play around with a text document and will post a bit later. Sorry for taking time, I'm quite busy at the office, so, as time allows, I'll post...;)

thanks mate, sorry for all the hassle :)

Yeah, sorry Neo. I had moved into larger offices, so the last few days was hectic for me. I WILL have a look tomorrow morning.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.