PDA

View Full Version : Solved: Start numbering over with alpha



Zack Barresse
11-13-2006, 04:00 PM
Okay, I'm having trouble with some VBA, which I'm not good with Word VBA at all. This is in 2007 B2TR, although it should be the same for 2003; I don't have 2003 on this machine to test with.

What I'm trying to do is apply a letter outlining to some selected text. I want this to be based on my style "MyAlpha" and each time it should restart at "A". I can get a numeric outline to start at 1. I've looked at the help files but it's no help. I think it's with the ListLevels, but I can't find a list of their constants. Any help would be appreciated. Here is my code:

Sub AddNewAlpha()
Selection.Style = ActiveDocument.Styles("MyAlpha")
Selection.Paragraphs(1).SelectNumber
With ListGalleries(wdNumberGallery).ListTemplates(7)
.ListLevels(1).ResetOnHigher = 0
.ListLevels(1).StartAt = 1
.ListLevels(1).LinkedStyle = "MyAlpha"
End With
ListGalleries(wdNumberGallery).ListTemplates(7).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdNumberGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
End Sub

Don't know what's needed or not. Also, will this work if there is already an outlining applied to the selection? Thanks. :)

Zack Barresse
11-16-2006, 02:01 PM
:bump:

mdmackillop
11-16-2006, 02:54 PM
Still :banghead:
I looked for a long time for a method to restart index lettering from A on each new page, and recall coming up with a crude workaround. It always seemed a big ommission from a word processing programme not to have the ability to handle letters!

Ken Puls
11-16-2006, 03:09 PM
Guys, I'm no Wordie, but you can do this manually, right? Or maybe I'm missing the point... dunno...

If I reformat my bullets to A, B C... through in some text, go to a new page, I can set my list to restart numbering there...

Is that what you guys are after? Seems to easy...

mdmackillop
11-16-2006, 03:13 PM
Hi Ken
The problems arose when you added/deleted entries on page 1. There is no automatic renumbering in following pages.

fumei
11-16-2006, 05:58 PM
Gotta tell you...I'm struggling with this.

BTW: ApplyListTemplateWithLevel is only in 2007. This does not exist in 2002.

I can get it to restart, but I can't get it to restart with letters. There is something in my dusty brain that recalls there is a way to do this, but so far I am stuck.

Ken Puls
11-16-2006, 07:17 PM
Hi Ken
The problems arose when you added/deleted entries on page 1. There is no automatic renumbering in following pages.

Ah, okay. My experience with Word is pretty limited, as you can tell. I can get most of what I need done through the UI. Although bullets and numbering have always been a bit tricky, I can't recall seeing this particular issue.

I'll leave this one to the Word experts and hopefully learn something from it. :)

Zack Barresse
11-17-2006, 10:11 AM
Hi guys, thanks for looking. I can also reset the bullets if they are numbered (or reset alpha to a numeric start). I just don't know enough about the Word object model to know what I'm looking at. I tried to find what some of these constants are and couldn't find any information on them. Frustrating.

And Ken, to answer your question, yes I can do this by hand. That is how I am currently doing it. The problem is, I am doing this for hundreds of entries over several hundred pages (5-10 usually per page). I hate doing things by hand, especially the same two processes, when I can set it to a single event (e.g. button combo, keyboard stroke, etc).

I have another question, related to the same project, but different question. I'll post it in another thread.

mdmackillop
11-17-2006, 10:28 AM
Hi Zack,
Can you post a small sample including your style?
Regards
Malcolm

Zack Barresse
11-17-2006, 11:14 AM
Here is a zip file with two documents in it, one with the styles applied (and unused characters stripped) and the other as it sits now, raw and unedited.

http://www.barresse.com/temp/CharEx.zip (couldn't upload it any other way)

Zack Barresse
11-17-2006, 12:33 PM
Let me pose this question: Is it possible to adjust a style so that when it is applied the numbering/outlining will always be at it's lowest level (i.e. 1, A)? I haven't found anything like that.

mdmackillop
11-17-2006, 12:38 PM
Hi Zack
This appears to set a selection to MyAlpha, resetting to A on each use.

Sub MyAlph()
Selection.Style = ActiveDocument.Styles("MyAlpha")
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
wdNumberGallery).ListTemplates(6), ContinuePreviousList:=False, ApplyTo:= _
wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
End Sub

Zack Barresse
11-17-2006, 12:43 PM
Hi Malcolm,

It does restart the ordering, but it is not applying the right style. The style I tried to save it to the template. Would I just change the ActiveDocument then to match?

mdmackillop
11-17-2006, 12:51 PM
I'm no great Style expert, but here's my version of your file. It shows the MyAlpha style when I run the code.

BTW Is there a reason why the Word File upload size limit is so small?

Zack Barresse
11-17-2006, 05:20 PM
That looks really great. The only thing seems to be the first level/indent of the style is in lower case, not upper. Anything we can do about that??

mdmackillop
11-17-2006, 05:29 PM
Are you looking to include the MySub2 style in the sub and format the "Header" and numbered items together?

mdmackillop
11-17-2006, 05:47 PM
This should format the whole selection to Alpha, then the first paragraph to MySub

Public Sub MyAlph()

selection.Style = ActiveDocument.Styles("MyAlpha")
selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
wdNumberGallery).ListTemplates(6), ContinuePreviousList:=False, ApplyTo:= _
wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
selection.Paragraphs(1).Style = ActiveDocument.Styles("MySub2")
End Sub

Zack Barresse
11-20-2006, 10:33 AM
It does Malcolm, and it works very well. Although it still has the same problem as before, it starts out with a lower case "A" on the first level of indent, whereas it should be capitalized.

mdmackillop
11-20-2006, 04:24 PM
I'm not getting that Zack. Here's a copy of my file. I changed the whole lot to Normal, then ran the enclosed code on the various sections

lucas
11-21-2006, 08:11 AM
I get the same thing Malcolm.....
I added text to the bottom of your last post and set its style to normal...then selected it and ran the myAlph routine and I got small letters instead of Caps....are we running it incorrectly?

Zack Barresse
11-21-2006, 10:44 AM
I get it started as lower case letters again, not uppercase. :(

mdmackillop
11-21-2006, 02:12 PM
I tried this in my office (Word 2000) and got the lower case as well. In looking at the available styles though, I'm seeing "A. MyAlpha" listed. If I used this, Capital numbering appeared. I fiddled around with this as a style name, but couldn't get it recognised.
Maybe it's time to call in the assistance of Dreamboat!!!

Anne Troy
11-21-2006, 04:42 PM
Okay. Y'all know I'm not VBA person, but I am pretty good with figuring out numbering. Though I've read all the posts, I'm not sure exactly what problem remains and which version (if specific) we're trying to get it to run in. I don't have 2007 to test. Do I need it?

Anne Troy
11-21-2006, 04:47 PM
My first thought is this, and I could be wrong. When I apply the style, there is no numbering. Then I go to modify the style (in 2000 'cause I think it's easier) and I see that numbering says NONE. Are you applying a style and THEN numbering it? Bad form. Lemme know what's up. We can prolly figger it out. :)

Zack Barresse
11-21-2006, 05:22 PM
Okay, what I'm doing is (in 2007, although it shouldn't matter - I don't think - I have 2002 & 2003 as well if need be) selecting my paragraphs (list), applying the style I created, then right click the first letter in the list and choose "Restart at A". Make sense?

Why does it seem like I'm making this more complicated than it has to be?! I just want to apply this style the way I do manually, but I want it starting over at A every time. Wow this is frustrating. :(

Anne Troy
11-25-2006, 10:54 AM
Ohhhhh.... (sorry to take so long--not getting notifs from any of the boards, WTF!!??)

See the title "Restart numbering with VBA" (?)

http://word.mvps.org/FAQs/Numbering/ListRestartMethods.htm

Zack Barresse
11-26-2006, 03:34 PM
I'll take a look at the link. Thanks Anne. :)

In the meantime, I actually got it to work. This is the code I used...

Sub SetStyle()
'
' SetStyle Macro
'
'
Selection.Style = ActiveDocument.Styles("MyAlpha")
With ListGalleries(wdNumberGallery).ListTemplates(7).ListLevels(1)
.NumberFormat = "%1."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleUppercaseLetter
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = wdUndefined
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Bold = wdUndefined
.Italic = wdUndefined
.StrikeThrough = wdUndefined
.Subscript = wdUndefined
.Superscript = wdUndefined
.Shadow = wdUndefined
.Outline = wdUndefined
.Emboss = wdUndefined
.Engrave = wdUndefined
.AllCaps = wdUndefined
.Hidden = wdUndefined
.Underline = wdUndefined
.Color = wdUndefined
.Size = wdUndefined
.Animation = wdUndefined
.DoubleStrikeThrough = wdUndefined
.Name = ""
End With
.LinkedStyle = "MyAlpha"
End With
ListGalleries(wdNumberGallery).ListTemplates(7).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdNumberGallery).ListTemplates(7), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
End Sub

This is with Word 2007.

Thanks for the link though, that is some great info! :yes

I'll mark this thread as Solved now.