Search code examples
vb.netheaderms-wordfootervisible

Word Headers / Footers Not Displaying


I have a ReportViewer that generates a word document. The program then opens the word document for the user to view it. My issue is when I open it using code, the headers and footers do not display.


Manually Opening Word Doc

Header / Footer display fine Header and Footer appear

Code Opening Word Doc

There is no visible headers / Footers here, but when I go to add one, the appear... No Header and Footer

I use the following code to open my word document:

Private MSWord As New Word.Application
Private WordDoc As New Word.Document

Private Sub OpenWordFullScreen(ByVal ReportName As String)
    Dim FolderPath As String = "C:\"

    WordDoc = MSWord.Documents.Open(FolderPath & "\" & ReportName & ".doc")
    MSWord.WindowState = Word.WdWindowState.wdWindowStateMaximize
    MSWord.Visible = True
End Sub

How can I make the header and footers visible?


Solution

  • Adding the following code after setting my MSWord to visible

    MSWord.ActiveWindow.View.Type = Word.WdViewType.wdReadingView
    

    Enabled me to view the header and footers as well as view the whole thing in FullScreen.