Macro runs although "If statement" is not properly closed by "EndIf".

A

andreas

Dear Experts: Below macro deletes the "DocProperty Author Field" from
all footers in my document. It runs FINE although I did NOT finish the
If-Statement with "End If", since I am getting an error message when
doing so (Error Message:("End If without If Block"). How come?

Dim sect As Section
Dim HF As HeaderFooter
Dim f As Field
Dim rng As range

For Each sect In ActiveDocument.Sections
For Each HF In sect.Footers
Set rng = HF.range
For Each f In rng.Fields

If f.Type = wdFieldDocProperty And InStr(UCase(f.Code),
"AUTHOR") Then f.Delete

Next f

Next HF
Next sect

End Sub
 
G

Greg Maxey

Because you put your then action in the same line of code as the If
statement:

Sub SM()
Dim i As Long
i = 1
'This is functionally the same
If i = 1 Then MsgBox i
'As this
If i = 1 Then
MsgBox i
End If
End Sub
 
A

andreas

Because you put your then action in the same line of code as the If
statement:

Sub SM()
Dim i As Long
i = 1
'This is functionally the same
If i = 1 Then MsgBox i
'As this
If i = 1 Then
  MsgBox i
End If
End Sub












--
Greg Maxey -  Word MVP

My web sitehttp://gregmaxey.mvps.org
Word MVP web sitehttp://word.mvps.org- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Hey Greg,

ok. Thank you very much. Regards, Andreas
 

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