2
Contributors
27
Replies
28
Views
6 Years
Discussion Span
Last Post by AndreRet
0

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.

0

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?

0

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.

0

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

0

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.

0

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

Edited by neosonic: n/a

0

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

Edited by AndreRet: n/a

0

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

0

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

0

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
0

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

0

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.

0

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

0

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

0

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

0

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.

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.