PDA

View Full Version : Number Field bookending a Style



FinancialAnalystKid
01-13-2005, 02:23 PM
Sometime in my document I'd like to add Numbers to the Styles in numeric order of course.

Maybe its a new style that replaces another one but I want the number to go on the first line of the paragraph to the left and to the right of that line. Possibly a field or something.

I came across this formula in a macro that did something similar:
"AUTONUMLGL \e "

The routine is below

Sub AddNum()

Selection.InsertBreak Type:=wdSectionBreakContinuous
Selection.Style = ActiveDocument.Styles("Slug1")
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \e ", PreserveFormatting:=False
Selection.TypeText Text:=vbTab
Slug1.Show
Selection.TypeText Text:=vbTab
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \e ", PreserveFormatting:=False
Selection.TypeParagraph
End Sub

Can someone explain how this works and how I can do the same for my template? I don't want a form called Slug1 as this suggests. There are no forms in my template at the moment.

Thanks for help!

Bilby
01-16-2005, 02:49 PM
Greetings, Firstly you don't need the form so you can safely delete the line Slug1.Show.
The code creates a new section, changes the style to the STYLE Slug1 (nothing to do with the form). A AUTONUM field is then inserted followed by a tab.

My guess is that the Slug1 UserForm is a sort of input that allows the user to add whatever text is to go between the two tabs.
If you replace the Style Slug1 with say Heading 1 which is a default style, and replace Slug1.Show with Selection.TypeText Text:="This is my sentence" you'll see exactly what this code does.

FinancialAnalystKid
01-17-2005, 08:51 AM
Thanks Bilby,

That makes sense.
Now I want this macro to run through the whole document and find all my Scene Heading styles and add this number bookending it.

Here's my code so far.

Sub AddNum()
Selection.InsertBreak Type:=wdSectionBreakContinuous
Selection.Style = ActiveDocument.Styles("Scene Heading")
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \e ", PreserveFormatting:=False
Selection.TypeText Text:=vbTab
Selection.TypeText Text:=vbTab
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \e ", PreserveFormatting:=False
Selection.TypeParagraph
End Sub

It only adds a "1 1" at the begining of the document before the firs tScen Heading style.

Can you help?

Bilby
01-17-2005, 07:34 PM
VBA Fun NOT isn't it? I should use the range object but I'm more comfortable with Selection.
anyway the following loops thro all paragraphs in the document

Sub AddNum()
Dim oDoc As Document
Dim pPara As Paragraph

Set oDoc = ActiveDocument
For Each pPara In oDoc.Paragraphs
'' Go thro' all paragraphs action on "Scene Heading" styled paras only
If pPara.Style = "Scene Heading" Then
pPara.Range.Select
With Selection
' collapse to start of para and insert field and tab
.Collapse Direction:=wdCollapseStart
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \e ", PreserveFormatting:=False
.TypeText Text:=vbTab

' collapse to end of text and insert tab and field
' Paragraph selection includes the marker, move back one character
pPara.Range.Select
.MoveEnd Unit:=wdCharacter, Count:=-1
.Collapse Direction:=wdCollapseEnd
.TypeText Text:=vbTab
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \e ", PreserveFormatting:=False
End With
End If
Next pPara
End Sub

FinancialAnalystKid
01-17-2005, 09:57 PM
Thanks again Bilby...

I got it to work by changing the name Scene Heading to ALL CAPS in the code.

Here's another quirk. My SCENE HEADING paragraphs formats are:
Norma + Font: All caps, Indent: Left 0.75" Right 0.75", Space before 12 pt

I'm trying to get the numbering flush left where my margin starts:
Left: 0.5"
Right: 0.5"
Yet keep the actual start of the paragraph at the indent.

I was thinking of developing a new style maybe called SCENE HEADING NUM where it would flush right and the numbering would go flush right then tab or indent the paragraph to the right to 0.75". Is this possible? Also, how do you set the numbering to the flush right margin of Right: 0.5"???

Thanks for all your help. It's getting there!

FAK!

Bilby
01-19-2005, 06:11 PM
Sorry I don't understand what your trying to do, maybe a sample would help?

I've never tried Auto numbering on the right margin but I suppose its the same as 'left' numbering, you can check it out in Help.

FinancialAnalystKid
01-21-2005, 10:12 AM
I tried to attach the word file in a message and it said it was wrong format or something.

Can I email it to you?

Jacob Hilderbrand
01-24-2005, 02:19 AM
You need to zip the Word document first. Then you will be able to attach it.

FinancialAnalystKid
01-24-2005, 11:35 AM
Cool.

I uploaded the template and a small sample. Basically, I want this numbering to book end the Scene Headings on the furthest left margin and furthest right margin as specified on the page margin setup. The headings need to remain in the same position at all times. If a field is 2 or 3 digits I don't want the headings to move to the right an extra 1 or 2 spaces.

Of course this will be done as a Macro and reversed when need be. The document is sometimes printed without the numbering and sometimes with.

Is this possible.

It's a Screenplay Template that I'm trying to build here.

Thanks,
FAK

Bilby
01-24-2005, 03:00 PM
Sorry FAK,

Your requirement is beyond me. With the indents as they are, the only way I can see of getting a number on the left hand margin is with an outline numbered style (which is easy enough). But to also get numbering on the right margin automatically is something I've never had to do.

The only way I can see of doing it is to include a tab position on the right hand margin and use the TabKeyMacroMove() to insert a tab & field on the margin.

I'll have a closer look at it tonight if I've got the time, but hopefully someone with more experience/creativity can help you out.

fumei
02-15-2005, 09:43 AM
You are not asking for much are you? It COULD be done, but it definitely not be trivial, especialy if you wanted to be able to toggle. And very especially if you want the text in between the numbering to remain constant. You specify if the digit is 3 characters you do NOT want the following text to move over 3 characters. This is not the way word processors function. You insert text, and any text to the right to moved over the amount of the inserted text.

Essentially, you need to put two form fields at the beginning and end of the first line of the paragraph with the specified style.

go to the start of the first line
pick up the Tab stops, and indents, for the style and store as PUBLIC variables
run logic on the tab stops and indents which includes checking for form fields at the begining of the line.

The logic is basic:

IF there is a form field, THEN
the numbering is in place, so
delete the form field
adjust the tab stops or indents
ELSE there is no form field
the numbering is not in place
insert a form field at the line start
adjust the tab stops
insert a form field at line end


Maybe use the SEQ field, rather than form field. It would be complicated.

Your sample doc does not really help it does not show EXACTLY what it is supposed to look like. There is no numbering on the right for example.

Can you duplicate what it is to look like?