A
andreas
Dear Experts:
Below macro is supposed to insert "hello" in all blank headers. It is
somehow not working. Why?
If I insert one (1) space in a header and alter the code line
(Len(....)) to ( If Len(hdr.range.Text) > 0 Then ..) the macro works.
But it does not work if the header is really blank. I find this very
strange.
Help is much appreciated. Thank you very much in advance. Regards,
Andreas
Sub Insert_Hello_In_Blank_Headers()
Dim rng As range
Dim sec As Section
Dim hdr As HeaderFooter
Dim fld As Field
For Each sec In ActiveDocument.Sections
For Each hdr In sec.Headers
If Len(hdr.range.Text) = 0 Then
hdr.range.Text = "hello"
End If
Next hdr
Next sec
End Sub
Below macro is supposed to insert "hello" in all blank headers. It is
somehow not working. Why?
If I insert one (1) space in a header and alter the code line
(Len(....)) to ( If Len(hdr.range.Text) > 0 Then ..) the macro works.
But it does not work if the header is really blank. I find this very
strange.
Help is much appreciated. Thank you very much in advance. Regards,
Andreas
Sub Insert_Hello_In_Blank_Headers()
Dim rng As range
Dim sec As Section
Dim hdr As HeaderFooter
Dim fld As Field
For Each sec In ActiveDocument.Sections
For Each hdr In sec.Headers
If Len(hdr.range.Text) = 0 Then
hdr.range.Text = "hello"
End If
Next hdr
Next sec
End Sub