Word 2007 Oddity: TableofContents

G

George Lee

The following code works in Office 2007 but not in Word 2007

Sub UpdateTables()
Dim myTOC As TableofContents
For Each myTOC In ActiveDocument.TablesOfContents
myTOC.Update
Next toc
End Sub

Specifically returning the error: A module is not a valid type. This error
is type of using a variable name that is the same as a module name. This is
not the case here. I can change the code to:

Sub UpdateTables()
Dim myTOC As object
For Each myTOC In ActiveDocument.TablesOfContents
myTOC.Update
Next toc
End Sub

This works fine but I lose my Intellisense in the compiler.

Anyone know why this is getting an error?
 
D

Doug Robbins - Word MVP

Try:

Sub UpdateTables()
Dim myTOC As TableofContents
For Each myTOC In ActiveDocument.TablesOfContents
myTOC.Update
Next myTOC
End Sub

Your code as posted had Next toc which means that you are changing the thing
that you are trying to iterate through partway through the process.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

George Lee

Thanks. It was an unfortunate typo. I meant either
Next myTOC
or just
Next

However, in either case, I still get the error message.
 
D

Doug Robbins - Word MVP

What is the name of the module in which you have the code?

The code does not cause an error here in a module named Module2

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

George Lee

Thanks. However that's what I said in my first post (see below). It's not
really a module name conflict (in this case, Module2, too). Additionally, it
doesn't happen in every case. That's why I'm asking if anyone has seen this
before.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top