[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 977
  • Last Modified:

Problems with TablesOfContents.Update in XP

Hi!

We have a number of macros set up for our book projects. Everything worked swell but after upgrading to Windows XP something strange happened. Suddenly TablesOfContents.Update wouldn't run.

Error message:

  "Method 'Update' of object 'TablesOfContents' failed"

Code:

  If (ActiveDocument.TablesOfContents.Count > 0) Then
        ActiveDocument.TablesOfContents(1).Update          '// We get here but the 'Update' method won't run
  End If


The method 'UpdatePageNumbers' works fine though.

If you could give me an explanation and/or a solution I would be most grateful.

Thanks!
0
Hermund
Asked:
Hermund
  • 7
  • 7
1 Solution
 
Joanne M. OrzechManager, Document Services CenterCommented:
Although I don't have Windows XP here, you could try re-recording the macro and see what code you get.  Get a document on your screen that contains a Table of Contents.  Then go to Tools, Macro, Record New Macro, give it a name, and go through the steps you want the macro to perform.  After ending recording the macro, press Alt F11 to view the code.  You can then see how and if it differs from your previous code.

0
 
Joanne M. OrzechManager, Document Services CenterCommented:
0
 
HermundAuthor Commented:
Hi!

Thanks for the reply!

I tried what you suggested and the following macro code was created:

Sub TOCupdate()
'
' TOCupdate Macro
' Macro recorded 17.11.2003 by hermund
'
    CommandBars("Outlining").Visible = True
    WordBasic.UpdateTableOfContents
End Sub


When I run this macro only the page numbers are updated, not the titles. Strange!

The Update TOC function (in Tools/Outlining) works fine.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Joanne M. OrzechManager, Document Services CenterCommented:
Did you try adding:

Dim TableOfContents as Object

?
0
 
HermundAuthor Commented:
I'm not sure I understand.

Like this?

Sub TOCupdate()
'
' TOCupdate Macro
' Macro recorded 17.11.2003 by hermund
'
    Dim TableOfContents As Object

    CommandBars("Outlining").Visible = True
    WordBasic.UpdateTableOfContents
End Sub
0
 
HermundAuthor Commented:
When you run the "Update TOC" commando you're asked whther to update page numbers only or update all. Default is page numbers only. That might be the reason why only the page numbers are updated when using TOCupdate.
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Usually, it is good practice to declare variables.  If you use Option Explicit, it will require you to declare all variables in your project.  But just try for now:

Dim TableOfContents As Object

Sub TOCupdate()
'
' TOCupdate Macro
' Macro recorded 17.11.2003 by hermund

    CommandBars("Outlining").Visible = True
    WordBasic.UpdateTableOfContents
End Sub
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Go to Visual Basic Help (Alt F11 - Help) and type in TOC.  


ActiveDocument.TablesOfContents.Update 'should update entire table
ActiveDocument.TablesOfContents.UpdatePageNumber 'should update page numbers only


 

 
0
 
HermundAuthor Commented:
I'm afraid it didn't help.

Could it be that there's a bug in the XP version?
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
hmmm - it could be - my home PC has XP and I'll have to try it there....will do that tonight as soon as I get home and let you know what I find.

0
 
HermundAuthor Commented:
Thanks a lot!
0
 
HermundAuthor Commented:
Hi there!

I figured out the problem now. I had called my method updateFields(). Apparently a new built-in method in the XP version had the same name. After changing the name everything worked swell.

Thanks for your help!

Hermund
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Great! - you can go to Community Support and ask for a refund of your points.
0
 
HermundAuthor Commented:
Done!

Thanks!

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now