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 / August 2007

Tip: Looking for answers? Try searching our database.

Macro that adds {listnum} to end of every numbered list in tables?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lyam - 14 Aug 2007 17:26 GMT
My documents are suffering from the numbering bug. I have a style called
"Table List Number" (TLN), which is based on No Style. All new tables restart
at 1 except when they are preceded by a bulleted list (which is based on
List). It would be easy enough to add the listnum field code to the end of
each table were it not for the fact that the documents are generated
automatically (using AuthorIT). This means that any hard-coding is kludged
whenever the documents are regenerated. What I think I need is a macro that
finds the last step in a table and adds the listnum field code to the end of
the step, but I don't know VB well enough to set this up. I think the logic
would be:
Search doc and find TLN
If next para tag is TLN, go there, else go to the end of this TLN and paste
{listnum \l 1\s 0}
Repeat to end of doc

Hoping someone can help me out.

Cheers,
lyam
Jean-Guy Marcil - 16 Aug 2007 03:30 GMT
lyam was telling us:
lyam nous racontait que :

> My documents are suffering from the numbering bug. I have a style
> called "Table List Number" (TLN), which is based on No Style. All new
[quoted text clipped - 16 lines]
> Cheers,
> lyam

Could you use Outline numbering?

Create a level one style that contains no bullet or numbering, that has a
font of one point and that is white, also set  the line spacing set at 0.7
points (Both values being the smallest size allowable).
This creates paragraphs that are practically invisible.
The level two would be your table style.
Whenever you want the numbering to restart, insert a level one paragraph.
You will have an invisible "restarter."

Or, if you do not like working with invisible paragraphs , set the  level
one style as hidden.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

lyam - 17 Aug 2007 01:48 GMT
Salut Jean-Guy,

Malheureusement, cela ne marche pas. I thought it would work, but it didn't.
Sigh.

Perhaps a simpler solution than my original macro idea would be to add some
kind of symbol or text to the end of each table in the source file (AuthorIT)
and then create a macro that searches the generated doc for this symbol and
replaces it with the listnum field code, which I have set up as an autotext.
This solution is not as elegant as my first macro idea, and it is certainly
not as elegant as your outline numbering idea, but it should work. And I
think I can create this simple macro all by myself!

Cheers
Signature

lyam

> lyam was telling us:
> lyam nous racontait que :
[quoted text clipped - 32 lines]
> Or, if you do not like working with invisible paragraphs , set the  level
> one style as hidden.
lyam - 17 Aug 2007 02:02 GMT
My so-called simple solution was not so simple after all. That is, I don't
know how to make the macro continue to the end of the document. "Replace All"
does not work because I am not replacing text with text; rather I am
replacing text with a command, and you can't type a command in the Replace
field.

Here is my macro:

Sub InsertListnum()
'
' InsertListnum Macro
' Macro recorded 8/16/2007 by lyam
'
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "~~"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute
   NormalTemplate.AutoTextEntries("LISTNUM").Insert Where:=Selection.Range
End Sub

How do I tell VB to repeat this process until all instances of ~~ are
replaced?
Signature

lyam

> Salut Jean-Guy,
>
[quoted text clipped - 47 lines]
> > Or, if you do not like working with invisible paragraphs , set the  level
> > one style as hidden.
Jean-Guy Marcil - 17 Aug 2007 02:45 GMT
lyam was telling us:
lyam nous racontait que :

> My so-called simple solution was not so simple after all. That is, I
> don't know how to make the macro continue to the end of the document.
[quoted text clipped - 29 lines]
> How do I tell VB to repeat this process until all instances of ~~ are
> replaced?

Try this:
'_______________________________________
Dim rgeFind As Range

Set rgeFind = ActiveDocument.Range

With rgeFind.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = "~~"
   .Replacement.Text = ""
   .Forward = True
   .Wrap = wdFindStop
   .Format = False
   .MatchCase = False
   .MatchWholeWord = False
   .MatchWildcards = False
   .MatchSoundsLike = False
   .MatchAllWordForms = False
   While .Execute
       NormalTemplate.AutoTextEntries("LISTNUM").Insert Where:=.Parent
       rgeFind.SetRange .Parent.End, ActiveDocument.Range.End
   Wend
End With

Application.Browser.Target = wdBrowsePage
'_______________________________________

I prefer using the Range object because the changes you make to Find and
Replace do not appear in the dialog box if you open it after running the
macro. When you use the Selection object, the Find/Replace parameters from
the code appear in the dialog box.

Also, you have to reset the Brower because Word thinks it is being helpful
by automatically setting the Browser to the last find you perform, even when
done by macro...

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jean-Guy Marcil - 17 Aug 2007 02:41 GMT
lyam was telling us:
lyam nous racontait que :

> Salut Jean-Guy,
>
> Malheureusement, cela ne marche pas. I thought it would work, but it
> didn't. Sigh.

Sorry to be blunt, but if it did not work, it means you did not set up your
styles correctly.
I have used the hidden style technique very often.

For more on styles and numbering, see
   http://www.shaunakelly.com/word/

As for your macro, see my other reply.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jean-Guy Marcil - 21 Aug 2007 03:13 GMT
Jean-Guy Marcil was telling us:
Jean-Guy Marcil nous racontait que :

> lyam was telling us:
> lyam nous racontait que :
[quoted text clipped - 12 lines]
>
> As for your macro, see my other reply.

I saw the document you sent me, and as I surmised... you did not set up the
styles appropriately. ;-)

You need to start with the "Spacer" style.

Select it in the "Style and Formatting..." pane (Format menu). Choose to
modify it (Right click on its name in the list).

Go to Numbering (Format button), use one of the proposed Outline style
(under the Outline tab) and reset it to its default.

Next, choose to customize it.

Click on "More" to display the extra options.

Delete the content of the "Number Format" field.

At the bottom, select "Spacer" in the list of style in the drop down next to
"Link level to style".

Then back at the top, select the second level (The "2" under  "Level").

In the "Number Format" field make sure that the auto number "1" is followed
by a "." (Or what ever you want following the auto number).

At the bottom, select "Table Style Number" in the list of style in the drop
down next to "Link level to style".

Finally, make all the Number position and text position adjustments here
(not in the tab dialog or paragraph dialog).

After that you can set the font or other paragraph attributes as you would
with any other styles (Except for left position, the first tab and the left
indent).

Now you have a Level 2 outline that acts as a level 1.

Whenever handling Outline styles, this is the way to go. Create the
bare-bone styles first (no numbering), then start form the first level style
and create the outline form there. In the example above, if you had needed a
third or a fourth style in the outline, you would have modified it there.
All numbering must be handled from the first level style.

In your case, the Spacer style was not part of the Outline numbering
scheme,, so it had no impact.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

lyam - 21 Aug 2007 06:22 GMT
Wow! I learned something today. And I thought I knew Word backwards and
forwards. In the document I sent you, I had set the outline level in the
Format > Style > Paragraph dialog, but I had not done anything in Numbering >
Outline.

Your solution works and I am delighted. Merci beaucoup.
Signature

lyam

> Jean-Guy Marcil was telling us:
> Jean-Guy Marcil nous racontait que :
[quoted text clipped - 61 lines]
> In your case, the Spacer style was not part of the Outline numbering
> scheme,, so it had no impact.
 
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.