Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word saving messes up Links

Status
Not open for further replies.

AlphaCat7

Technical User
Jul 18, 2007
4
US
I made a Macro to add new customers to a table and keep track of there data in a seperate file. All the files are kept on a server and need to be able to be avalible to everyone on the Local network.

The command I used to make the link is -




vFileLocation = ActiveDocument.FullName


'Close and Return to table

Selection.GoTo What:=wdGoToBookmark, Name:="Click"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.Delete


Selection.Document.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"MACROBUTTON Temp3 Press When Done", PreserveFormatting:=False







ActiveDocument.Close


Documents("Customer Database.doc").Activate
Selection.MoveRight 1


Set aHLink = ActiveDocument.Hyperlinks.Add( _
Anchor:=Selection.Range, _
Address:=vFileLocation, TextToDisplay:="-Notes-")

It seems to make a good link until I save the table. After that all the links are messed up.

Any ideas on hoew to fix the problem?
 
After that all the links are messed up.
My mind reading ability is a little off right now.....

Also, could you please use the TGML code tags, thanks. Oh, and try to not use all that empty space.

I am trying to find meaning with the code you posted. You may find it helpful (for you too) to expand some use of comments.

You Select a bookmark (Click) then delete it.

Why?

And you do not need to do it that way. You do not need to select it at all. Just delete it, if that is what you want to do...but I am having a hard time figuring out what you are trying to do.

So, you Select a bookmark, delete it, add a macrobutton field to the location of the deleted bookmark. Then you close the document without saving it - which seems kind of pointless.

You activate another document, and move the Selection one character....why I don't know. You then make a hyperlink at that point, using the target the path/filename of the previously changed (but not saved) and closed document.

Then.....something about "It seems to make a good link until I save the table." As you make absolutely no mention of any table...hard to say. Plus...what does "save the table" mean, anyway?????

You can save document files....but not just tables. Please be a bit more clear. Apparently "saving the table" messes things up...in an unexplained way. Messes up how?

Is there a hyperlink, but it goes to the wrong place?
Is there a hyperlink, but it does not work at all?
Is the hyperlink no longer there?

Hard to suggest how to fix the "problem" when it is not clear what, exactly, the problem is.

faq219-2884

Gerry
My paintings and sculpture
 
Sorry for being so hard to understand. I am self taught at this so I ask you to bear with me.

As for saving the file I didn't worry about including a command to save it scince Word automatically asked you to save it. Part of that is done earler in the macro.

All I was trying to do was show how i got the file name and location and how I got the hyperlink.

The table is in a Word document Moving the one space for del. just gets the curser in the right spot from the cell it was in when the new window opened. (again that part was earler in the macro). The problem sems to be that when the hyperlink is first made the link works great. After i hit save (I don't close the document) Word changes the Hyperlink and it no longer connects to the file.

Again I appoligise for the messy and un-clear work. This is my first real attempt at doing something like this.
 
At the bottom of the window where you type in your post is a link "Process TGML". Click it. It shows how to use TGML tags to format parts of your post. Code whould be posted using the
Code:
 tags.

Don't worry about the self-taught thing.  Most of us ARE self-taught...with help from places like this.

Please try and be very, very clear when posting.  I suggest looking at the FAQ on posting.  It may help.

Sorry, but it is still not clear.  One of the critical items mentioned in the FAQ on posting is answering questions.

You did not answer a single question I asked regarding what is messed up.  I asked specific questions, and you did not answer any of them.

Please describe - step-by-step - what is happening.  All I can do is infer.

1.  You running code from DocA.
2.  You open DocB, so it is ActiveDocument.
3.  You make the variable vFileLocation the FullName of the ActiveDocument (ie. DocB)
4.  You close DocB. (After doing something with deleting a bookmark...I don't know why...is this relevant?)
5.  You activate DocA (maybe....who knows.... Documents("Customer Database.doc").Activate may, or may not, be the originating document running the code)

Not sure what "when the new window opened." means.  Does it mean when you activate Customer Database.doc?????

6.  You move the Selection.  BTW:  it will increase your code eficiently to NOT use and move Selection.  Cell is tables can be referenced directly.

7.  You add a hyperlink, using the Address the variable of the previous (now closed) document FullName.

It works.  But when you save the file...it no longer works.  Although WHAT is not working is not stated...still.

is this remotely close to the situation?

OK.  The other stuff is a distraction, I think, and not relevant.  Word does indeed sometimes change hyperlink address. It gets funny that way, as it makes decisions regarding relative vs absolute addressing.  You may also want to check File > Properties and see what you have in the hyperlink base field.

After creating a hyperlink in Word, hovering over that hyperlink displays your intended path. However, once you click Save, Word may change the link to a path that is relative to the Word document’s location, a virtual path that begins with …/

Is this the case?  Does it now shows something like that?

To prevent Word from changing your hyperlinks, take the following steps:

1.  Click Tools | Options. 

2.  On the General tab, click the Web Options button. 

3.  In the Web Options window, click the Files tab. 

4.  Clear the check box for “Update links on save.” 

5.  Click OK to save your preferences. 




faq219-2884

Gerry
[url=http://www3.telus.net/public/fumei/]My paintings and sculpture[/url]
 
Gerry
I really appreciate your time and understanding on this. Sorry again for not being clear. I guess it is easy to see when I have the problem compared to what I am saying. I will try harder next time to be more precise in what I need and try to use the TGML tags as well.

You did hit on the relevant part of the question. Word was updating the links on save. Is there another way to make a link, a command button or something that word will not update? The reason I ask is that my machine will not be the only one using the file and I can't get all of them to not update on save.

I'll look up how to directly refrence the cell and see if I can work it in somehow. Thanks for the insight.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top