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