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 / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Word does not recognize the New Links

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
maperalia - 01 Nov 2005 00:47 GMT
I have a program (see below)which is run from excel and that does the
following:
1.- Save as the excel template file (template.xls) using the cells to create
the filename.
2.- Open the word template file (template.doc)
3.- Update the links automatically using the same path and filename in the
step 1

After the program finish I check the link in the word file by clicking “Alt
+ F9” to verify that the new links have taken place. Although the new link
took place I “Select all” under edit menu then I select “Update Link” and I
got the following message:
“Word in unable to create a link to the object you specified, Please insert
the object directly into your file without creating a link”
After I click “OK” I got this message in all my links:
“Error! Not a valid link".

So I discover that even thought the link is there is not reading it.
Could you please tell me how can I fix this problem?

Thanks in advance.
Maperalia

‘&&&&&&&&&&&&&&&&&&&&&&&
Option Explicit

Public Sub SaveExcelOpenWordAndUpdateLinks()
Dim sPath As String
sPath = SaveExcelTemplatelAsSaveAs
OpenWordAndUpdateLinks (sPath)
End Sub

Function SaveExcelTemplatelAsSaveAs() As String

Dim WO As String
Dim grdprp As String
Dim sFilename As String
Dim Progname As String
Dim Filename As String
Dim myDateTime As String

WO = Worksheets("summary BLR").Range("M10")
myDateTime = Format(Worksheets("summary BLR").Range("M9").Value, "yyyymmdd")
Filename = "" & WO & ".grdprp." & myDateTime & ""
Progname = "C:\test\" & Filename & ".xls"
ActiveWorkbook.SaveCopyAs Progname

SaveExcelTemplatelAsSaveAs = Progname

End Function

'***********OPEN THE TEMPLATE WORD FILE ****************************
Sub OpenWordAndUpdateLinks(sPathToExcelFile As String)

Dim wordApp As Object
Dim fNameAndPath As String
Dim Filename As String

fNameAndPath = "C:\test\template.doc"
Set wordApp = CreateObject("Word.Application")
wordApp.Documents.Open (fNameAndPath)
wordApp.Visible = True
wordApp.Activate
'wordApp.Run ("C:\test\template.doc!UpdateLinks")

wordApp.Run macroname:="UpdateLinks", vArg1:=sPathToExcelFile
Set wordApp = Nothing

End Sub
'**********************************************************
'NEXT MACRO IS LOCATED IN THE WORD DOCUMENT

Option Explicit

Public Sub UpdateLinks(sPath As String)
Dim alink As Field
Dim linktype As Range
Dim linkfile As Range
Dim linklocation As Range
Dim i As Integer
Dim j As Integer
Dim linkcode As Range
Dim Message, Title, Default, Newfile
Dim counter As Integer

counter = 0
For Each alink In ActiveDocument.Fields
If alink.Type = wdFieldLink Then

Set linkcode = alink.Code
i = InStr(linkcode, Chr(34))

Set linktype = alink.Code
linktype.End = linktype.Start + i
j = InStr(Mid(linkcode, i + 1), Chr(34))

Set linklocation = alink.Code
linklocation.Start = linklocation.Start + i + j - 1

linkcode.Text = linktype & sPath & linklocation

End If
Next alink

End Sub

‘&&&&&&&&&&&&&&&&&&&&&&&
macropod - 01 Nov 2005 09:03 GMT
Hi maperalia,

From what I can tell, the problem is caused by the fact that paths in fields
need to be separated by either double back-slashes (i.e. '\\') or single
forward slashes (i.e. '/'), but your code only generates single back-slashes
(i.e. '\'). Also, if your filename or path has spaces anywhere in it, the
lot must be enclosed in double quotes.

You may be able to correct this by changing:
linkcode.Text = linktype & sPath & linklocation
to:
linkcode.Text = linktype & Chr(34) & Replace(sPath, "\", "\\") & Chr(34) &
linklocation

Cheers

> I have a program (see below)which is run from excel and that does the
> following:
[quoted text clipped - 5 lines]
>
> After the program finish I check the link in the word file by clicking
"Alt
> + F9" to verify that the new links have taken place. Although the new link
> took place I "Select all" under edit menu then I select "Update Link" and
I
> got the following message:
> "Word in unable to create a link to the object you specified, Please
insert
> the object directly into your file without creating a link"
> After I click "OK" I got this message in all my links:
[quoted text clipped - 90 lines]
>
> '&&&&&&&&&&&&&&&&&&&&&&&
maperalia - 01 Nov 2005 17:58 GMT
sMacropod;
Thanks for your quick response. I made the changes in my code with your new
statement. However, when I ran the program I noticed that the links has the
double back-slashes but when I click update link I got this message in all my
links:
 "Error! No topic specified.
This error is different than before. I wonder if you can help me to find out
to fix this problem.

Best regards.
Maperalia

> Hi maperalia,
>
[quoted text clipped - 124 lines]
> >
> > '&&&&&&&&&&&&&&&&&&&&&&&
macropod - 01 Nov 2005 21:22 GMT
hi maperalia,

Seems I overdid the changes. All you need is:
linkcode.Text = linktype & Replace(sPath, "\", "\\") & linklocation

Cheers

> sMacropod;
> Thanks for your quick response. I made the changes in my code with your new
[quoted text clipped - 136 lines]
> > >
> > > '&&&&&&&&&&&&&&&&&&&&&&&
maperalia - 01 Nov 2005 23:00 GMT
Macropod;
Thanks very much it is working wonderful!!!!!!!!. I really appreciate your
supporting in this matter.

Best regards.
Maperalia

> hi maperalia,
>
[quoted text clipped - 154 lines]
> > > >
> > > > '&&&&&&&&&&&&&&&&&&&&&&&
maperalia - 03 Nov 2005 16:18 GMT
Macropod;
One last question. I have noticed that after I ran the macro all my links
get gray pattern. Althought this gray pattern does not show up in my prints
out. I wonder if I  can I turn it off and on when is neccesary

Best regards
Maperalia

> Macropod;
> Thanks very much it is working wonderful!!!!!!!!. I really appreciate your
[quoted text clipped - 161 lines]
> > > > >
> > > > > '&&&&&&&&&&&&&&&&&&&&&&&
macropod - 05 Nov 2005 00:11 GMT
Hi maperalia,

The shading isn't caused by the macro - it's caused by your settings under
Tools|Options|View - 'field shading'.

Cheers

> Macropod;
> One last question. I have noticed that after I ran the macro all my links
[quoted text clipped - 169 lines]
> > > > > >
> > > > > > '&&&&&&&&&&&&&&&&&&&&&&&
 
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.