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

Word delete section breaks by DA

DA
Sun Aug 29 22:58:58 CDT 2004

Hi David

This is probably not the best way of doing it, but I just
hacked this together and it works..

'------------------
Sub RemBlankBreaks()
With ActiveDocument
Dim vVar As Boolean
bVar = True
While bVar
.Sections.Last.Range.Select
While Right(Selection, 1) = vbCrLf Or _
Right(Selection, 1) = vbCr Or _
Right(Selection, 1) = vbLf
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Wend
If Selection.Characters.Count <= 1 Then
Selection.Collapse Direction:=wdCollapseEnd
Selection.Delete
Else
bVar = False
End If
Wend
Selection.Collapse Direction:=wdCollapseEnd
End With
End Sub
'----------------------

Hope this helps,
Dennis

>-----Original Message-----
>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
>
>
>
>
>.
>

Word delete section breaks by DA

DA
Sun Aug 29 23:07:36 CDT 2004

Sorry.. just noticed a spelling mistake.
The line:
Dim vVar as Boolean

should obviously be:
Dim bVar as Boolean

Unless you've got Option Explicit set, the mistake won't
stop the code from running, but I thought I better say
something before people point it out.

Dennis.
>-----Original Message-----
>Hi David
>
>This is probably not the best way of doing it, but I
just
>hacked this together and it works..
>
>'------------------
>Sub RemBlankBreaks()
>With ActiveDocument
>Dim vVar As Boolean
>bVar = True
>While bVar
> .Sections.Last.Range.Select
> While Right(Selection, 1) = vbCrLf Or _
> Right(Selection, 1) = vbCr Or _
> Right(Selection, 1) = vbLf
> Selection.MoveEnd Unit:=wdCharacter, Count:=-1
> Wend
> If Selection.Characters.Count <= 1 Then
> Selection.Collapse Direction:=wdCollapseEnd
> Selection.Delete
> Else
> bVar = False
> End If
>Wend
>Selection.Collapse Direction:=wdCollapseEnd
>End With
>End Sub
>'----------------------
>
>Hope this helps,
>Dennis
>
>>-----Original Message-----
>>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
>>
>>
>>
>>
>>.
>>
>.
>

Re: Word delete section breaks by Jezebel

Jezebel
Sun Aug 29 23:52:16 CDT 2004

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
>
>
>
>



Re: Word delete section breaks by Peter

Peter
Mon Aug 30 00:09:30 CDT 2004

Hi david epsom dot com dot au

Do you really all Section breaks in the document or just Section breaks at the end of the
document. Also, if you mean Section breaks at the end of the document are they
immediately before the documents final paragraph mark?

Cheers - Peter


"david epsom dot com dot au" <david@epsomdotcomdotau>, said:

>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
>
>
>

HTH + Cheers - Peter


Re: Word delete section breaks by DA

DA
Mon Aug 30 01:49:12 CDT 2004

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
>>
>>
>>
>>
>
>
>.
>

Re: Word delete section breaks by Jezebel

Jezebel
Mon Aug 30 02:11:33 CDT 2004

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
> >>
> >>
> >>
> >>
> >
> >
> >.
> >



Re: Word delete section breaks by david

david
Wed Sep 01 19:19:37 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
> > >>
> > >>
> > >>
> > >>
> > >
> > >
> > >.
> > >
>
>



Re: Word delete section breaks by david

david
Wed Sep 01 19:21:23 CDT 2004

All section breaks at the end of the document.
Is there a final paragraph mark after the last
hard section break? Can you delete it? Can
you select it? Is it in any range?

(david)

"Peter Hewett" <nospam@xtra.co.nz> wrote in message
news:bfd5j0dgurfmgokj2jhabk1qqmkaanel61@4ax.com...
> Hi david epsom dot com dot au
>
> Do you really all Section breaks in the document or just Section breaks at
the end of the
> document. Also, if you mean Section breaks at the end of the document are
they
> immediately before the documents final paragraph mark?
>
> Cheers - Peter
>
>
> "david epsom dot com dot au" <david@epsomdotcomdotau>, said:
>
> >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
> >
> >
> >
>
> HTH + Cheers - Peter
>



Re: Word delete section breaks by Peter

Peter
Thu Sep 02 06:14:24 CDT 2004

Hi david epsom dot com dot au

I'm still not sure that I understand *exactly* what you want to do. Or maybe more
accurately I'm not sure how you end up with a document with multiple section breaks at the
end!

Anyway, if your document has one or more section breaks immediately before the final
paragraph mark of the document this code will delete them:

Public Sub DeleteSectionsAtEOD()
Dim rngEOD As Word.Range

' Move the start of the range object over any consecutive
' contiguous Section breaks at the end of the document

' Setup collapsed range at the end of the document
Set rngEOD = ActiveDocument.Content
rngEOD.Collapse wdCollapseEnd

' vbFormFeed is the character Word uses for all types of Section breaks
' MoveStartWhile with a count of wdBackward returns a negative number
If rngEOD.MoveStartWhile(vbFormFeed, wdBackward) < 0 Then

' Delete the section break(s)
rngEOD.Delete
End If
End Sub

HTH + Cheers - Peter


"david epsom dot com dot au" <david@epsomdotcomdotau>, said:

>All section breaks at the end of the document.
>Is there a final paragraph mark after the last
>hard section break? Can you delete it? Can
>you select it? Is it in any range?
>
>(david)
>
>"Peter Hewett" <nospam@xtra.co.nz> wrote in message
>news:bfd5j0dgurfmgokj2jhabk1qqmkaanel61@4ax.com...
>> Hi david epsom dot com dot au
>>
>> Do you really all Section breaks in the document or just Section breaks at
>the end of the
>> document. Also, if you mean Section breaks at the end of the document are
>they
>> immediately before the documents final paragraph mark?
>>
>> Cheers - Peter
>>
>>
>> "david epsom dot com dot au" <david@epsomdotcomdotau>, said:
>>
>> >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
>> >
>> >
>> >
>>
>> HTH + Cheers - Peter
>>
>


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
> >
> >
> >
> >
>
>