Re: Word delete section breaks by david
david
Thu Sep 02 17:48:21 CDT 2004
In WordBasic, I moved to the end of the document, then deleted
the last character -- which took out 1 trailing section break.
Using the Word application object model, the code has become so
complex that I'm never sure what I've got at the end of the document,
so I'm quite happy to have more explicit code with testing.
It's interesting to compare the two examples:
last section:
.Sections.Last.Range
.Sections(.Sections.Count).Range
delete:
selection.Delete
.Range(pRange.Start - 1, pRange.End).Delete
My preference is to go with Range rather than Select, even
though this makes the code less intuitive, because I have
an idea that Select implies use of the GUI, and might work
differently if the application was hidden and not activated.
.Last. /looks/ better than .Section.Count Jezebel, is this just
coding practice or am I missing something?
Question: is a Paragraph Mark the same as a lf/cr? or is there
a different test for that?
(david)
"Jezebel" <dwarves@heaven.com.kr> wrote in message
news:uDYFYCmjEHA.2776@TK2MSFTNGP10.phx.gbl...
> Hardly a problem, just a matter of your definition of 'blank'. Mine was a
> maximum of one character (presumptively a paragraph mark) plus any number
of
> spaces. But you could be a lot more sophisticated with your test, eg
>
> If pRange.Text Like "[ " & vbcr & vblf & "]*" then
>
>
>
>
>
> "DA" <infoscene@nospam.winshop.com.au> wrote in message
> news:272101c48e5d$751d3e50$a501280a@phx.gbl...
> > Hi Jezebel,
> >
> > Problem with this is that you're taking for granted that
> > the final section has a single character. What about if
> > your blank sections have 2 or more carriage returns -
> > linefeeds - or both?
> >
> > I couldn't get my brain into gear this morning, got any
> > other ideas on how we can cover the above (apart from
> > that rather ugly looking if statement I posted earlier)?
> >
> > Dennis.
> >
> > >-----Original Message-----
> > >Try this:
> > >
> > > Dim pRange As Word.Range
> > >
> > > Set objTarget = GetObject(str_CombinedFileName)
> > >
> > > With objTarget
> > > Do
> > >
> > > 'Get a reference to the final section
> > > Set pRange = .Sections(.Sections.Count).Range
> > >
> > > 'If not empty, then we're done
> > > If Len(Trim(pRange)) > 1 Then
> > > Exit Do
> > > End If
> > >
> > > 'Delete it and go round again
> > > .Range(pRange.Start - 1, pRange.End).Delete
> > > Loop
> > > End With
> > >
> > > MsgBox "DONE"
> > >
> > >This deletes any final sections that contain a maximum
> > of one character
> > >(assumed to be a paragraph mark) plus any number of
> > leading and trailing
> > >spaces.
> > >
> > >"david epsom dot com dot au" <david@epsomdotcomdotau>
> > wrote in message
> > >news:%238rH0HijEHA.1040@TK2MSFTNGP09.phx.gbl...
> > >> I would like to delete any section breaks at the end
> > of the document, if
> > >> there are any. Assuming that I have an open document
> > object, how would I
> > >go
> > >> about this? This is what I have so far:
> > >>
> > >> 6030 Set objTarget = GetObject(str_CombinedFileName)
> > >>
> > >> 6040 Set objApp = objTarget.Application
> > >>
> > >> 6041 objApp.Visible = True
> > >>
> > >> 6042 objApp.Activate
> > >>
> > >>
> > >>
> > >>
> > >
> > >
> > >.
> > >
>
>
"Jezebel" <dwarves@heaven.com.kr> wrote in message
news:O4x$i0kjEHA.384@TK2MSFTNGP10.phx.gbl...
> Try this:
>
> Dim pRange As Word.Range
>
> Set objTarget = GetObject(str_CombinedFileName)
>
> With objTarget
> Do
>
> 'Get a reference to the final section
> Set pRange = .Sections(.Sections.Count).Range
>
> 'If not empty, then we're done
> If Len(Trim(pRange)) > 1 Then
> Exit Do
> End If
>
> 'Delete it and go round again
> .Range(pRange.Start - 1, pRange.End).Delete
> Loop
> End With
>
> MsgBox "DONE"
>
> This deletes any final sections that contain a maximum of one character
> (assumed to be a paragraph mark) plus any number of leading and trailing
> spaces.
>
> "david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
> news:%238rH0HijEHA.1040@TK2MSFTNGP09.phx.gbl...
> > I would like to delete any section breaks at the end of the document, if
> > there are any. Assuming that I have an open document object, how would I
> go
> > about this? This is what I have so far:
> >
> > 6030 Set objTarget = GetObject(str_CombinedFileName)
> >
> > 6040 Set objApp = objTarget.Application
> >
> > 6041 objApp.Visible = True
> >
> > 6042 objApp.Activate
> >
> >
> >
> >
>
>