A
Associates
Hi,
I was wondering if anyone might be able to help me here with the insertion
of a new section in VBA. This is for word 03.
My aim here is to make it easier for our staff to write up a report document
for their client. Because so far we have a lot of inconsistencies in our
staff's reports. One may use a different style or font size and so on. So i
was asked to write a program in word VBA to mitigate the problem. I got some
advice from this forum a while ago that some suggested me to use autotext
(for it's easier than programming it from scratch). so i have used it and
must confess that it does make it easier to achieve what i wanted without
using extensive programming here.
So the report consists of as follows in that order
Covering page
TOC
Executive summary (optional)
Sections
Bibliography (optional)
Glossary (optional)
Appendixes (optional)
Anyway, i made up a userform that would allow user to choose which of those
sections they need to make up their report. so that works fine.
The issue i'm having here is in "sections" section. In here, this is what it
looks like
Section 1 Inventory Re-structuring
whereby Section 1 is automatically generated by word and Inventory
Re-structuring is what user types in.
Now, i have a macro program here called "insert a section". This will add a
new section to the report in the "sections" section.
The problem is when clicking on "insert a section". It put in the section
but not continuation.
For example. we have Section 1 (at the start), then add a new section - it
should be Section 2 ... But it doesn't, it puts in Section 1 ... and of
course this causes a problem in the page numbering in the footer. Instead of
getting page 2, it says page 1. How do i work around this?
Here is the code for inserting a section
Sub InsertNewSection()
Selection.InsertBreak Type:=wdSectionBreakOddPage
Selection.Style = ActiveDocument.Styles("Section Heading 1")
ListGalleries(wdOutlineNumberGallery).ListTemplates(7).Name = ""
Selection.Range.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries( _
wdOutlineNumberGallery).ListTemplates(7),
ContinuePreviousList:=True, _
ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
Selection.TypeText Text:=InputBox("Please enter the section heading:",
"Enter Section Heading")
Selection.TypeParagraph
Selection.Font.Name = "Tahoma"
End Sub
Sub marginstyle()
StyleName = "Section Heading 1"
For Each oStyle In ActiveDocument.Styles
If oStyle.NameLocal = StyleName Then GoTo Setup
Next oStyle
ActiveDocument.Styles.Add Name:=StyleName, Type:=wdStyleTypeParagraph
Setup:
With ActiveDocument.Styles(StyleName)
.AutomaticallyUpdate = False
.BaseStyle = ActiveDocument.Styles(wdStyleHeading1)
.NextParagraphStyle = "Normal"
.Font.Name = "Tahoma"
End With
With ActiveDocument.Styles(StyleName).Font
.Size = 20
.ColorIndex = wdGreen
.Name = "Tahoma"
End With
Selection.Font.Name = "Tahoma"
End Sub
I don't know how to stop it from starting at 1. Thank you very much in advance
I was wondering if anyone might be able to help me here with the insertion
of a new section in VBA. This is for word 03.
My aim here is to make it easier for our staff to write up a report document
for their client. Because so far we have a lot of inconsistencies in our
staff's reports. One may use a different style or font size and so on. So i
was asked to write a program in word VBA to mitigate the problem. I got some
advice from this forum a while ago that some suggested me to use autotext
(for it's easier than programming it from scratch). so i have used it and
must confess that it does make it easier to achieve what i wanted without
using extensive programming here.
So the report consists of as follows in that order
Covering page
TOC
Executive summary (optional)
Sections
Bibliography (optional)
Glossary (optional)
Appendixes (optional)
Anyway, i made up a userform that would allow user to choose which of those
sections they need to make up their report. so that works fine.
The issue i'm having here is in "sections" section. In here, this is what it
looks like
Section 1 Inventory Re-structuring
whereby Section 1 is automatically generated by word and Inventory
Re-structuring is what user types in.
Now, i have a macro program here called "insert a section". This will add a
new section to the report in the "sections" section.
The problem is when clicking on "insert a section". It put in the section
but not continuation.
For example. we have Section 1 (at the start), then add a new section - it
should be Section 2 ... But it doesn't, it puts in Section 1 ... and of
course this causes a problem in the page numbering in the footer. Instead of
getting page 2, it says page 1. How do i work around this?
Here is the code for inserting a section
Sub InsertNewSection()
Selection.InsertBreak Type:=wdSectionBreakOddPage
Selection.Style = ActiveDocument.Styles("Section Heading 1")
ListGalleries(wdOutlineNumberGallery).ListTemplates(7).Name = ""
Selection.Range.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries( _
wdOutlineNumberGallery).ListTemplates(7),
ContinuePreviousList:=True, _
ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
Selection.TypeText Text:=InputBox("Please enter the section heading:",
"Enter Section Heading")
Selection.TypeParagraph
Selection.Font.Name = "Tahoma"
End Sub
Sub marginstyle()
StyleName = "Section Heading 1"
For Each oStyle In ActiveDocument.Styles
If oStyle.NameLocal = StyleName Then GoTo Setup
Next oStyle
ActiveDocument.Styles.Add Name:=StyleName, Type:=wdStyleTypeParagraph
Setup:
With ActiveDocument.Styles(StyleName)
.AutomaticallyUpdate = False
.BaseStyle = ActiveDocument.Styles(wdStyleHeading1)
.NextParagraphStyle = "Normal"
.Font.Name = "Tahoma"
End With
With ActiveDocument.Styles(StyleName).Font
.Size = 20
.ColorIndex = wdGreen
.Name = "Tahoma"
End With
Selection.Font.Name = "Tahoma"
End Sub
I don't know how to stop it from starting at 1. Thank you very much in advance