Newbie here with a major headache from . I have searched and searched and I'm confident and hopeful that you fine folks can help me!
I'm trying to achieve a last page footer (unable to tell how long the doc will ultimately be) that is populated by a macro. I found the solution to achieving a last page only footer by using an IF field:
{ IF { PAGE} = { NUMPAGES} {FILENAME \p} }
Now how do I code the macro so that the filename within the IF field is populated by the macro results instead?
Here is my code so far - Any help at all is gratuitously appreciated at the maximum!
[VBA]
Sub AutoNew()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
End If
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
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
Selection.EndKey Unit:=wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Open "C:\cycomdat\lh_macro.txt" For Input As 1
While Not EOF(1)
Line Input #1, data_$
caseno$ = WordBasic.[Left$](data_$, 10)
If caseno$ = "[{CASENO}]" Then
CASENO2$ = Mid(data_$, 11)
WordBasic.Insert CASENO2$
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Font.TimesNewRoman.Size = 7
End If
Wend
Close 1
Selection.MoveDown
Selection.TypeParagraph
Open "C:\cycomdat\lh_macro.txt" For Input As 1
While Not EOF(1)
Line Input #1, data_$
PATHANDFILENAME$ = WordBasic.[Left$](data_$, 19)
If PATHANDFILENAME$ = "[{PATHANDFILENAME}]" Then
PATHANDFILENAME2$ = Mid(data_$, 20)
' Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
' Selection.Font.Size = 9
End If
Wend
Close 1
WordBasic.Insert PATHANDFILENAME2$
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
If ActiveDocument.ProtectionType = wdNoProtection _
Then ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
[/VBA]