View Single Post
 
Old 07-12-2018, 02:10 PM
Ken Leidner's Avatar
Ken Leidner Ken Leidner is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Sep 2016
Posts: 7
Ken Leidner is on a distinguished road
Default Saving information into Footer doesn't close footer

I have the following VBA code that ends with the screen in draft mode and the edit footer dialog box open. I have to click the red X to close the footer edit and then change to print view.



What am I missing? VBA should beable to do it all? Point me in the right direction.

Otherwise the code does what it should.



Code:
Sub DateFooter()
' get first day of the month
MyDate = DateSerial(Year(Date), Month(Date), 1)
' what day of the week is it - 1 = sun 2= mon ... Fri = 6
w1 = Weekday(MyDate)
' set second firday of the month
w = 6 - w1 + 7 + 1
MyDate2 = DateSerial(Year(Date), Month(Date), w)
My3 = Format(MyDate2, "dddd, mmmm dd yyyy")
'      this doesn't work current page number is always 1
'      For i = 1 To ActiveDocument.Sections.Count
'       With ActiveDocument.Sections(i)
 '       .Footers(wdHeaderFooterPrimary).Range.Text = My3 & String(175, " ") & "Page " & Selection.Information(wdActiveEndPageNumber) & " of " &         Selection.Information(wdNumberOfPagesInDocument)
'        End With
' thit works but when I get back to the document I need to close the footer and
' I am still left in draft mode
 ActiveDocument.Sections(ActiveDocument.Sections.Count) _
        .Footers(wdHeaderFooterPrimary).Range.Select
    With Selection
  '      .Paragraphs(1).Alignment = wdAlignParagraphCenter
        .TypeText Text:=My3 & String(175, " ") & "Page "
        .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "PAGE ", PreserveFormatting:=True
        .TypeText Text:=" of "
        .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "NUMPAGES ", PreserveFormatting:=True
    End With
    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    Else
        ActiveWindow.View.Type = wdPrintView
    End If

End Sub

Last edited by macropod; 07-12-2018 at 08:45 PM. Reason: Added code tags
Reply With Quote