Group: microsoft.public.word.vba.general
From: =?Utf-8?B?QXNzb2NpYXRlcw==?=
Date: Sunday, March 30, 2008 6:58 PM
Subject: Re: trouble in inserting a section to the report

Thanks Doug,

The sections now works fine. Thank you for your help.

"Doug Robbins - Word MVP" wrote:

> Sorry, I don't understand you question. I will say however that you should
> the styles that you want to use defined in the template and then you should
> just apply the applicable style.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Associates" wrote in message
> news:B443A10A-3150-44E2-A1DA-4B06F696F3C0@microsoft.com...
> > Hi Doug,
> >
> > I think that your question below has just made me realise what's happening
> > and causing this issue to me.
> >
> > "Don't you have the numbering setup in the Section Heading 1 style?"
> >
> > I did a few experiments here and concluded that the issue here is due to
> > the
> > fact that different styles have been used here.
> >
> > I have a template .dot for "sections". It has got "Section Heading 1
> > style"
> > with the numbering setup in it. Then, i highlighted them all and added to
> > autotext called "section". The reason for this is as i mentioned earlier
> > that
> > each of those components in the report namely TOC, executive summary,
> > section, bibliography and appendixes have their own different header and
> > footer. For example, the footer of Executive Summary is different from
> > that
> > of Section. So, i thought if i could create template for each of these
> > parts
> > and added them to autotext, it'd save me a lot of pain from having to
> > write
> > VBA codes to make up headers and footers.
> >
> > Anyway, in the actual myReport.dot, i have just created a new style
> > "Section
> > Heading 1 style" with the numbering setup in it and saved the template. It
> > is
> > the same style i created for template "sections". MyReport.dot has codes
> > that
> > would put in all these autotext to the report. The code is as follows
> > ActiveDocument.AttachedTemplate.AutoTextEntries("executivesummary").Insert
> > _
> > Where:=Selection.Range, RichText:=True
> > ActiveDocument.AttachedTemplate.AutoTextEntries("sections").Insert _
> > Where:=Selection.Range, RichText:=True
> >
> > After executing these lines of codes, I was hoping that there would be
> > only
> > one "Section Heading 1 style" but I was wrong. There are two styles now.
> > One
> > is called "Section Heading 1" and the other one called "Section Heading 1
> > Justified ...". No wonder the Section numbering doesn't work. "Section 1."
> > from the template sections.dot has now become "Section Heading 1 Justified
> > ..."
> >
> > My question is whether there is a way of changing the style to "Section
> > Heading 1" from "Section Heading 1 Justified..." for "Section 1." that is
> > from template sections.dot or is there any other better ways to get
> > around
> > this?
> >
> > Thank you in advance
> >
> >
> >
> >
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> I don' understand why you would be using this code
> >>
> >> srange.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
> >> wdOutlineNumberGallery).ListTemplates(7),
> >> ContinuePreviousList:=True, _
> >> ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
> >> wdWord10ListBehavior
> >>
> >> According to the Visual Basic Help file, the ListFormat property of a
> >> range
> >> is Read Only. That however may not be correct as the examples in the
> >> Help
> >> file would seem to indicate otherwise. Also, according to the Visual
> >> Basic
> >> Help file in Word 2007, there are only two DefaultListBehaviours -
> >> wdWord8ListBehaviour and wdWord9ListBehaviour
> >>
> >> Don't you have the numbering setup in the Section Heading 1 style?
> >>
> >> --
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
> >>
> >> "Associates" wrote in message
> >> news:BB9CC7F6-0B9A-407F-A09A-ACAFC1B67EDD@microsoft.com...
> >> > Thank you Doug, for your reply.
> >> >
> >> > Doug, there is nothing wrong with the code you wrote down there. It
> >> > inserts
> >> > a section break and puts in "Test" text on the new page. The problem
> >> > i'm
> >> > having is that as follows (sorry, not good at explaining so i'd try my
> >> > best
> >> > to explain what i mean to you)
> >> >
> >> > remember when i said in the earlier post that i use autotext method to
> >> > insert page for Coverpage, TOC, Executive Summary, Sections, and
> >> > Bibliography
> >> > respectively to make up a complete report. Each of these pages have
> >> > their
> >> > own
> >> > header and footer, different from one another. So i decided to use
> >> > autotext.
> >> > So imagine, when user double-clicks on the template dot file called
> >> > "Myreport", a userform comes up with a list of those components and
> >> > "Generate
> >> > report" button. Once, the button is pressed, all these components are
> >> > inserted into the document as follows
> >> > Coverpage
> >> > TOC
> >> > Executive Summary
> >> > Section 1.
> >> > Bibliography
> >> >
> >> > The problem i'm having here is the "Section 1. ". This "Section 1" is
> >> > created through Customised Outline Numbered List. So at the start, the
> >> > "Section 1. " is already there. Now, i have a button called "Insert New
> >> > Section". When user wants to click it it should add a new Section
> >> > (which
> >> > is
> >> > the next after whatever the previous Section is) on the next page. So
> >> > in
> >> > this
> >> > case, we have got "Section 1. " already. The new Section should be
> >> > "Section
> >> > 2." on the next page.
> >> >
> >> > The code that you wrote there for me does insert the section break (a
> >> > new
> >> > page). Then, i modified it as below to suit my need.
> >> >
> >> > Dim srange As Range
> >> > Dim ssection As Section
> >> > Dim i As Long
> >> > i = Selection.Information(wdActiveEndSectionNumber)
> >> >
> >> > Set srange = Selection.Sections(1).Range
> >> >
> >> > srange.Collapse wdCollapseEnd
> >> > srange.InsertBreak wdSectionBreakNextPage
> >> >
> >> > Set srange = ActiveDocument.Sections(i + 1).Range
> >> > srange.Collapse wdCollapseStart
> >> >
> >> > srange.Style = ActiveDocument.Styles("Section Heading 1")
> >> >
> >> > srange.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
> >> > wdOutlineNumberGallery).ListTemplates(7),
> >> > ContinuePreviousList:=True, _
> >> > ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
> >> > wdWord10ListBehavior
> >> >
> >> > srange.Text = "Test"
> >> >
> >> > The result after running this code is that it inserts a new section
> >> > break
> >> > as
> >> > well as inserts "Section 1. Test". The problem here is it should be
> >> > "Section
> >> > 2. Test", not "Section 1. Test". Because "Section 1." is already there
> >> > right
> >> > from the start.
> >> >
> >> > It seems to be unable to track which Section number it's at.
> >> >
> >> > Sorry for this lengthy explanation (can't think of a better way). I
> >> > hope
> >> > this would help you understand my situation here.
> >> >
> >> > Thank you once again in advance
> >> >
> >> >> > srange.InsertBreak wdSectionBreakNextPage
> >> >> >
> >> >> > srange.Style = ActiveDocument.Styles("Section Heading 1")
> >> >> >
> >> >> > srange.ListFormat.ApplyListTemplate
> >> >> > ListTemplate:=ListGalleries( _
> >> >> > wdOutlineNumberGallery).ListTemplates(7),
> >> >> > ContinuePreviousList:=True, _
> >> >> > ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
> >> >> > wdWord10ListBehavior
> >> >
> >> >
> >> > "Doug Robbins - Word MVP" wrote:
> >> >
> >> >> Can you clarify what you mean by:
> >> >>
> >> >> " it added a new section but started from Section 1 (when it should be
> >> >> "Section 2"). "
> >> >>
> >> >> Dim srange As Range
> >> >> Set srange = Selection.Sections(1).Range
> >> >> srange.Collapse wdCollapseEnd
> >> >> srange.InsertBreak wdSectionBreakNextPage
> >> >>
> >> >> Definitely inserts a section break after the section in which the
> >> >> selection
> >> >> is located.
> >> >>
> >> >> However, to be really sure that your subsequent commands are executing
> >> >> on
> >> >> the desired part of the document, you may need to use
> >> >>
> >> >> Dim srange As Range
> >> >> Dim ssection As Section
> >> >> Dim i As Long
> >> >> i = Selection.Information(wdActiveEndSectionNumber)
> >> >> Set srange = Selection.Sections(1).Range
> >> >> srange.Collapse wdCollapseEnd
> >> >> srange.InsertBreak wdSectionBreakNextPage
> >> >> Set srange = ActiveDocument.Sections(i + 1).Range
> >> >> srange.Collapse wdCollapseStart
> >> >> srange.Text = "Test"
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Hope this helps.
> >> >>
> >> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> >> services on a paid consulting basis.
> >> >>
> >> >> Doug Robbins - Word MVP
> >> >>
> >> >> "Associates" wrote in message
> >> >> news:FEE95EBE-FAEE-4EB9-BE02-28386175A23A@microsoft.com...
> >> >> > Hi Doug,
> >> >> >
> >> >> > yes, i didn't apply the style to the selection. sorry
> >> >> >
> >> >> > I have modified the code as follows
> >> >> >
> >> >> > Dim srange As Range
> >> >> > Set srange = Selection.Sections(1).Range
> >> >> > srange.Collapse wdCollapseEnd
> >> >> > srange.InsertBreak wdSectionBreakNextPage
> >> >> >
> >> >> > srange.Style = ActiveDocument.Styles("Section Heading 1")
> >> >> >
> >> >> > srange.ListFormat.ApplyListTemplate
> >> >> > ListTemplate:=ListGalleries( _
> >> >> > wdOutlineNumberGallery).ListTemplates(7),
> >> >> > ContinuePreviousList:=True, _
> >> >> > ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
> >> >> > wdWord10ListBehavior
> >> >> >
> >> >> > srange.Text = InputBox("Please enter:", "Enter Section Heading")
> >> >> >
> >> >> > Everything works fine except that there is still a problem with the
> >> >> > continuation of the Sections. it added a new section but started
> >> >> > from
> >> >> > Section
> >> >> > 1 (when it should be "Section 2"). Not sure if this is to do with
> >> >> > the
> >> >> > autotext. I actually used autotext to perform the insertion of
> >> >> > "Section
> >> >> > 1"
> >> >> > at
> >> >> > the start and then, i use this code to allow user to insert more
> >> >> > sections
> >> >> > to
> >> >> > the report.
> >> >> >
> >> >> > Thank you in advance
> >> >> >
> >> >> > "Doug Robbins - Word MVP" wrote:
> >> >> >
> >> >> >> You are applying the style to the Selection which at that point is
> >> >> >> not
> >> >> >> in
> >> >> >> the new Section.
> >> >> >>
> >> >> >> --
> >> >> >> Hope this helps.
> >> >> >>
> >> >> >> Please reply to the newsgroup unless you wish to avail yourself of
> >> >> >> my
> >> >> >> services on a paid consulting basis.
> >> >> >>
> >> >> >> Doug Robbins - Word MVP

Safety Articles | Usenet Groups | Usenet News | Bluegrass