B
Brandon
I have been working on this problem for some time now and I just can't
figure it out. I wrote this macro to handle the Table export from
Telelogic's DOORS and create a document from it. It steps through the
table (Table 2 in template), finds certain things, counts the Table and
Figure captions and then converts it to text. It then steps through and
creates caption numbers, centers tables and figures, etc. When you step
through the macro manually (F8) everything works fine. When you run it
at full speed it skips certain Table centering steps and refuses to
update the numPages field. Here is one of the portions that isn't
working:
For TableNum = 1 To TableCount
If Selection.Find.Execute(FindText:="Table ?-?:",
MatchCase:=True, MatchWildcards:=True, Forward:=True) Then
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Style = ActiveDocument.Styles("Caption")
With CaptionLabels("Table")
.NumberStyle = wdCaptionNumberStyleArabic
.IncludeChapterNumber = True
.ChapterStyleLevel = 1
.Separator = wdSeparatorHyphen
End With
Selection.HomeKey Unit:=wdLine
Selection.InsertCaption Label:="Table",
TitleAutoText:="InsertCaption1", _
Title:="", Position:=wdLine, ExcludeLabel:=0
Selection.TypeText (": ")
With Selection.ParagraphFormat
.KeepWithNext = True
.OutlineLevel = wdOutlineLevelBodyText
End With
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.MoveUp Unit:=wdLine, Count:=1
End If
Next TableNum
As you can see, it finds the "Table ?-?:" text, deletes it, and inserts
a numbered caption. Then it steps down one line, centers the Table
below, and steps back up before searching for the next one. Seems
simple to me and it works fine most of the time, but it invariably does
not center 2 or 3 tables in the doc at full speed. Again, works fine
with F8.
The other issue is update numPages. I target the field in a known cell
in Table 1, then use "Selection.Fields.Update" to update it.
Stepping through works fine AND placing the same code at the beginning
of the macro works too; however, this doesn't capture the TOC addition
and formatting changes.
I have tried adding pauses to the code thinking it was just running too
quick, but that doesn't really make sense, nor does it work.
Anybody seen this problem before?
figure it out. I wrote this macro to handle the Table export from
Telelogic's DOORS and create a document from it. It steps through the
table (Table 2 in template), finds certain things, counts the Table and
Figure captions and then converts it to text. It then steps through and
creates caption numbers, centers tables and figures, etc. When you step
through the macro manually (F8) everything works fine. When you run it
at full speed it skips certain Table centering steps and refuses to
update the numPages field. Here is one of the portions that isn't
working:
For TableNum = 1 To TableCount
If Selection.Find.Execute(FindText:="Table ?-?:",
MatchCase:=True, MatchWildcards:=True, Forward:=True) Then
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Style = ActiveDocument.Styles("Caption")
With CaptionLabels("Table")
.NumberStyle = wdCaptionNumberStyleArabic
.IncludeChapterNumber = True
.ChapterStyleLevel = 1
.Separator = wdSeparatorHyphen
End With
Selection.HomeKey Unit:=wdLine
Selection.InsertCaption Label:="Table",
TitleAutoText:="InsertCaption1", _
Title:="", Position:=wdLine, ExcludeLabel:=0
Selection.TypeText (": ")
With Selection.ParagraphFormat
.KeepWithNext = True
.OutlineLevel = wdOutlineLevelBodyText
End With
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.MoveUp Unit:=wdLine, Count:=1
End If
Next TableNum
As you can see, it finds the "Table ?-?:" text, deletes it, and inserts
a numbered caption. Then it steps down one line, centers the Table
below, and steps back up before searching for the next one. Seems
simple to me and it works fine most of the time, but it invariably does
not center 2 or 3 tables in the doc at full speed. Again, works fine
with F8.
The other issue is update numPages. I target the field in a known cell
in Table 1, then use "Selection.Fields.Update" to update it.
Stepping through works fine AND placing the same code at the beginning
of the macro works too; however, this doesn't capture the TOC addition
and formatting changes.
I have tried adding pauses to the code thinking it was just running too
quick, but that doesn't really make sense, nor does it work.
Anybody seen this problem before?