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 / October 2006

Tip: Looking for answers? Try searching our database.

Problem updating links to Excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff Eckermann - 14 Oct 2006 02:04 GMT
I'm a newbie in programming with Word (don't know much about Word in
general), though I'm pretty familiar with VBA in Excel and Access.  What I
am trying to do is illustrated by the following code, executed from a module
in Excel:

Dim rngFirms as Range          'These are Excel ranges
Dim rngFirmNo as Range
Dim wdApp as Word.Application
Dim wdSrc as Word.Document
Dim strPath as ThisWorkBook.Path
Dim strSrcFile as "Report.doc"
Dim i as Integer

Set wdApp = New Word.Application
wdApp.Options.UpdateLinksAtOpen = True
Application.Calculation = xlCalculationManual

Set rngFirms = Worksheets("2006").Range("A4:A114")    'List of firms on
which to produce reports
Set rngFirmNo = Worksheets("Tables").Range("A3")        'Set firm number for
report

For i = 1 to rngFirms.Rows.Count
   rngFirmNo = rngFirms.Cells(i , 1)
   Application.Calculate               'Populate tables and charts based on
firm no
   Set wdSrc = wdApp.Documents.Open(FileName:=strPath & "\Report.doc",
Visible:=False)
   Set wdSrc = wdSrc.SaveAs(strPath & "\Reports\Report No " & rngFirmNo)
   wdSrc.Close
Next i

'(Various cleanups here)

The Word document contains links to tables and charts in Excel; the Excel
values are reset on each iteration; the links in the Word document should
update each time it is opened.  The document can then be saved using the
number for the applicable firm.  And so on.

I tested this code with an old version of the spreadsheet and document (from
a similar past exercise).  It worked well.  Transferring the same code to
new setup, AFAICT set up the same way as the old, the code fails: the links
do not update; each document has the same data in it.

The help file tells me that "wdSrc.Fields.Update" will update all the fields
in the document.  So it does; now all of the correct data is there.  But the
tables have resized themselves, and are now too large to fit on the page, so
that part of the data is no longer visible.  This does not happen when I
update the links manually.

I also tried iterating through "wdSrc.InLineShapes(i).LinkFormat.Update",
but with exactly the same result as "wdSrc.Fields.Update" (and slower).

I have searched through the NG archives, but haven't found anything to help
(probably my deficiency).  I would be glad of any suggestions, or even
explanations (in the event of no available fix).  The prospect of doing this
exercise manually is not enticing.

TIA
Cindy M. - 16 Oct 2006 11:13 GMT
Hi Jeff,

Some thoughts...

1. The problem with the information not updating automatically could be due to
"fixes" for security issues: http://support.microsoft.com?kbid=330079

2. The resizing could be due to using a different version of Office than the
one in which the file set was originally created. Try creating (part of the
report) "from scratch" in a new document.

3. Or, this could be a problem with something else... If you press Alt+F9 you
should see the fieldcodes maintaining the links (if you don't, put one of the
table objects "in line with text", then try again). Could you copy/paste the
contents of a LINK field into your reply, please? I'm interested in the
switches it's using.

> I'm a newbie in programming with Word (don't know much about Word in
> general), though I'm pretty familiar with VBA in Excel and Access.  What I
[quoted text clipped - 53 lines]
> explanations (in the event of no available fix).  The prospect of doing this
> exercise manually is not enticing.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
Jeff Eckermann - 16 Oct 2006 13:53 GMT
Cindy,
Thank you very much for your suggestions.  Comments below.

> Hi Jeff,
>
[quoted text clipped - 3 lines]
> due to
> "fixes" for security issues: http://support.microsoft.com?kbid=330079

Interesting: though I get the prompt about updating links every time the
file is opened.

> 2. The resizing could be due to using a different version of Office than
> the
> one in which the file set was originally created. Try creating (part of
> the
> report) "from scratch" in a new document.

Yes, the new version of the document was created using Office 2003; I am
using Office XP.  I will try what you suggest.

> 3. Or, this could be a problem with something else... If you press Alt+F9
> you
[quoted text clipped - 4 lines]
> contents of a LINK field into your reply, please? I'm interested in the
> switches it's using.

LINK Excel.Sheet.8 "C:\\Jeff\\Benchmarking\\Report Generation\\2006
Benchmark Data 12 Oct 06.xls" "Member Summary!R29C1:R67C8" \a \p  \*
MERGEFORMAT

>> I'm a newbie in programming with Word (don't know much about Word in
>> general), though I'm pretty familiar with VBA in Excel and Access.  What
[quoted text clipped - 73 lines]
> reply
> in the newsgroup and not by e-mail :-)
Cindy M. - 19 Oct 2006 14:47 GMT
Hi Jeff,

> > 3. Or, this could be a problem with something else... If you press Alt+F9
> > you
[quoted text clipped - 8 lines]
> Benchmark Data 12 Oct 06.xls" "Member Summary!R29C1:R67C8" \a \p  \*
> MERGEFORMAT

OK, the \* MergeFormat switch should be retaining sizing information applied
to the *graphic object* (not the chart) in Word. And I can see it's not being
changed to MergeFormatINET - a possible source for the problem.

So I'm inclined to think it may be something version-related ("Yes, the new
version of the document was created using Office 2003; I am using Office
XP."). The one other thing I can suggest trying is to create the Chart as a
separate sheet (not an object "on" a worksheet). Open it in Print Preview and
change the margins so that the chart (the actual print area inside the
margins) is the size you want to have in the Word document. I've had good luck
with that approach when Excel charts "get out of control".

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

Rate this thread:






 
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.