InsertCaption Error

T

Terry Moriarty

I'm getting an error of "Error! No text of specified style
in document" when I insert a table caption for a table.

I insert a new table, format the header and insert the
caption whenever Category Name in my data source changes.
Then I fill in the table with rows until the category name
changes again.

Every thing is working except for this insertcaption error
in my document.

The code is below.

Thanks is advance for any assistance any one can provide
me,
Terry Moriarty


target.Tables.Add Range:=myRange, NumRows:=1,
NumColumns:=k - 1
currentTable = currentTable + 1
Set ttab = target.Tables(currentTable)
ttab.Select
With ttab.Borders
.InsideLineStyle = wdLineStyleSingle
.OutsideLineStyle = wdLineStyleSingle
End With

' Insert the Caption for the Table

ttab.Range.InsertCaption Label:=wdCaptionTable, _
Title:=": " & CurrentCat, _
Position:=wdCaptionPositionAbove
 
C

Cindy M -WordMVP-

Hi Terry,
I'm getting an error of "Error! No text of specified style
in document" when I insert a table caption for a table.

I insert a new table, format the header and insert the
caption whenever Category Name in my data source changes.
Then I fill in the table with rows until the category name
changes again.

Every thing is working except for this insertcaption error
in my document.
I'm not sure what's causing the error, at this point. But before we explore that, I'd like to help you clean up your code a bit. You're doing a lot of contortions, getting a hold of an manipulating your table; it could be done a bit more smoothly (and this might help the other problem, as well)

Try this:

Dim ttab as Word.Table

Set ttab = target.Tables.Add(Range:=myRange, _
NumRows:=1, NumColumns:=k - 1)
With ttab.Borders
.InsideLineStyle = wdLineStyleSingle
.OutsideLineStyle = wdLineStyleSingle
End With

' Insert the Caption for the Table

ttab.Range.InsertCaption Label:=wdCaptionTable, _
Title:=": " & CurrentCat, _
Position:=wdCaptionPositionAbove

Note, too, that you may want to check whether you have a CAPTION style defined in the document. If you've removed that, this could be the problem. Are you able to insert a caption over the user interface?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 
T

Terry Moriarty

Thanks,

I'm never quite sure when to use the object specific form
of a command vs. the Selection form. In cleaning up the
code, are you saying to use the object specific form of
the command rather than Selection.?

I'm having the same problem in any Word document that uses
the normal.dot template. I think that somehow I corrupted
it. Is there a way to get the default version of
normal.dot back?

Thanks,
Terry
-----Original Message-----
Hi Terry,

I'm not sure what's causing the error, at this point. But
before we explore that, I'd like to help you clean up your
code a bit. You're doing a lot of contortions, getting a
hold of an manipulating your table; it could be done a bit
more smoothly (and this might help the other problem, as
well)
Try this:

Dim ttab as Word.Table

Set ttab = target.Tables.Add(Range:=myRange, _
NumRows:=1, NumColumns:=k - 1)
With ttab.Borders
.InsideLineStyle = wdLineStyleSingle
.OutsideLineStyle = wdLineStyleSingle
End With

' Insert the Caption for the Table

ttab.Range.InsertCaption Label:=wdCaptionTable, _
Title:=": " & CurrentCat, _
Position:=wdCaptionPositionAbove

Note, too, that you may want to check whether you have a
CAPTION style defined in the document. If you've removed
that, this could be the problem. Are you able to insert a
caption over the user interface?
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 
C

Cindy M -WordMVP-

Hi Terry,
I'm never quite sure when to use the object specific form
of a command vs. the Selection form. In cleaning up the
code, are you saying to use the object specific form of
the command rather than Selection.?
What you should use depends on the context :) If you're actually working with the current selection, then use that. If you're working completely with ranges, then you should be able to use a range object. I couldn't see a particular reason to actually select the table, based on what you posted in your original code, so I did leave that part out...
I'm having the same problem in any Word document that uses
the normal.dot template. I think that somehow I corrupted
it. Is there a way to get the default version of
normal.dot back?
Rename Normal.dot to NormalOLD.dot, then start up Word. Word will generate a clean copy when it can't find one anywhere.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 
G

Guest

I'm stumped. Where is Normal.Dot hidden away at? A
search for Normal.Dot didn't find it. It is a hidden file?

Thanks,
Terry
-----Original Message-----
Hi Terry,

What you should use depends on the context :) If you're
actually working with the current selection, then use
that. If you're working completely with ranges, then you
should be able to use a range object. I couldn't see a
particular reason to actually select the table, based on
what you posted in your original code, so I did leave that
part out...
Rename Normal.dot to NormalOLD.dot, then start up Word.
Word will generate a clean copy when it can't find one
anywhere.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 
C

Cindy M -WordMVP-

I'm stumped. Where is Normal.Dot hidden away at? A
search for Normal.Dot didn't find it. It is a hidden file?
It might be located in a hidden FOLDER (as is the case by default on newer combinations of Windows and Office). You can unhide the folders via Windows Explorer/Tools/Folder options/View. You may also want to make sure the display of file extensions is activated so that you pick up the .dot

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 

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