It is not a dumb question. You mean in the recorded macro code? I guess that is what you are asking. The answer is, yes the If..Else statements come from the actions taken (clicks and keystrokes). I recorded the macro precisely as follows.
1. Clicked Tools > Macro > Record New Macro
2. Changed the macro title to "FooterText"
3. Clicked OK.
4. Clicked View > Headerfooter
5. Clicked Switch between Header and Footer button
6. Typed "This is text in the footer of Section 1"
7. Clicked Close on the HeaderFooter toolbar
8. Clicked the Stop button on the macro recorder
The code in Sub FooterText() above is the result. I changed nothing, added nothing. This is actually my point. Recording macros records what you DO. Now what you DO may require certain states and conditions, and the code takes care of that. I will try to break this down in more detail. You start to record the macro....
You click View > Headerfooter.
To view headerfooters, you must be in PrintView, so VBA checks to see what view you are in, and makes sure you are in PrintView.
Code:
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
[b]ActiveWindow.ActivePane.View.Type = wdPrintView[/b]
End If
It then makes the View the current header.
Code:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
All of this is caused by clicking View > Headerfooter.
Clicking Switch from Header and Footer causes VBA to check if the View is Header (the .IsHeader), and if it is, switch to Footer.
Code:
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Then typing the text:
Code:
Selection.TypeText Text:="This is text in the footer of Section 1"
and clicking the Close button:
Code:
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
The code results from the actions taken, based on the logic built into the Object Model. Such as to View headers and footers you must be in PrintView.
The written code must, obviously, also use the appropriate logic of the Object Model. The difference is that the written macro uses a different object, to get the same result.
The recorded macro uses View - so the user interface is actioned so you can SEE the header, then change to footer, so you can type the text ("This is text in the footer of Section 1") into the footer. The recorded code results from the logic requirements of those steps.
The written macro uses the footer object itself and simply states its text IS "This is text in the footer of Section 1".
This may be a subtle difference, but recording macros creates code that (in this case)
makes the footer text "xxxxxx". There is a step by step actioning to get there. Multiple steps are need to do that.
With the written code, there is ONE action, ONE Write operation. The footer text IS "This is text in the footer of Section 1".
Now some will say (with justification) that this matters little with the power and speed of current machines. This is true, and I admit I am an old fart from the time when every single I/O (read and write operations) counted.
Still, I believe that, as much as possible, we should try and write code that is clear, AND efficient.
Enough. I have gone on waaaaaay too much.
Gerry
My paintings and sculpture