Error - the Range cannot be deleted

  • Thread starter Karthik Palaniappan
  • Start date
K

Karthik Palaniappan

Hello Everyone,

We have a subroutine called "setFooterString" that is supposed to override the left section of the footer in a Word document if parameter "boolOverrideLeftFooterOnly" is set to true.


Private Sub setFooterString(ByRef objHeaderFooter As HeaderFooter, ByVal strTextString As String, ByVal boolOverrideLeftFooterOnly As Boolean)

On Error GoTo handler_Error_Function


With objHeaderFooter.Range
.Style = wdStyleFooter
.Font.Size = 10
If boolOverrideLeftFooterOnly = True Then
'If we qualify setRange with "objHeaderFooter.Range" it does work in cases where the left section of the footer is a word supported text

.SetRange Start:=.Start, End:=getLeftFooterLen(objHeaderFooter)


End If
.Text = strTextString
End With

Exit Sub
handler_Error_Function:

If Err.Number <> 0 And Err.Number <> cdlCancel Then
Call GlobalErrorHandler(Err.Number, Err.Description, Err.Source)
GoTo handler_Garbage_Collection
End If

handler_Garbage_Collection:


End Sub


If the current left section of footer is a user enterred custom text say "abc", the subroutine works fine(overrides left section of footer) .

If the current left section of footer is a word supported text such as date, page number etc. the subroutine generates an error saying "the range cannot be deleted" upon reaching the following line in code:
.Text = strTextString

Shouldn't it behave consistently.

Also, strangely above mentioned error does not occur if we replace following line
.SetRange Start:=.Start, End:=getLeftFooterLen(objHeaderFooter)
with
objHeaderFooter.Range.SetRange Start:=.Start, End:=getLeftFooterLen(objHeaderFooter)

Can someone please help us understand the problem? Is it a bug in VBA or is it bad coding?

Thanks,
Karthik
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?S2FydGhpayBQYWxhbmlhcHBhbg==?=,
We have a subroutine called "setFooterString" that is supposed to override the left
section of the footer in a Word document if parameter "boolOverrideLeftFooterOnly" is set
to true.
If the current left section of footer is a user enterred custom text say "abc", the
subroutine works fine(overrides left section of footer) .
If the current left section of footer is a word supported text such as date, page
number etc. the subroutine generates an error saying "the range cannot be deleted" upon
reaching the following line in code:I think you're not showing us enough of your code. What does getLeftFooterLen do?

My guess is that the value being set as the End character value for the range is probably
somewhere WITHIN a field code. (Fields are what Word uses to display information such as a
date or a page number. Press Alt+F9 to toggle the codes on/off in a document and you'll
see what I mean).
.SetRange Start:=.Start, End:=getLeftFooterLen(objHeaderFooter)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the
newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top