Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to add a picture to header with VB.NET

I have code to add a footer but i can't add a header, can you help me please :(

VB
oWord = DirectCast(CreateObject("Word.Application"), word.Application)
      oWord.Visible = False
      oDoc = oWord.Documents.Open("C:\exibit\Quotation No. " & usquot & "\" & a & ".docx")
      If oWord.ActiveWindow.View.SplitSpecial <> word.WdSpecialPane.wdPaneNone Then
          oWord.ActiveWindow.Panes(2).Close()
      End If
      If oWord.ActiveWindow.ActivePane.View.Type = word.WdViewType.wdNormalView Or _
          oWord.ActiveWindow.ActivePane.View.Type = word.WdViewType.wdOutlineView Then
          oWord.ActiveWindow.ActivePane.View.Type = word.WdViewType.wdPrintView
      End If
      oWord.ActiveWindow.ActivePane.View.SeekView = word.WdSeekView.wdSeekCurrentPageHeader
      If oWord.Selection.HeaderFooter.IsHeader = True Then
          oWord.ActiveWindow.ActivePane.View.SeekView = word.WdSeekView.wdSeekCurrentPageFooter
      Else
          oWord.ActiveWindow.ActivePane.View.SeekView = word.WdSeekView.wdSeekCurrentPageHeader

      End If
      oWord.Selection.ParagraphFormat.Alignment = word.WdParagraphAlignment.wdAlignParagraphJustifyHi
      oWord.Selection.TypeText(Text:="Project name: " & fMain.TextBox1.Text & vbTab & vbTab & "Page: ")
      oWord.Selection.Fields.Add(Range:=oWord.Selection.Range, Type:=word.WdFieldType.wdFieldPage)
      oWord.Selection.TypeText(Text:=vbNewLine & "Quotation No. " & fMain.TextBox13.Text)

      oWord.ActiveWindow.ActivePane.View.SeekView = word.WdSeekView.wdSeekMainDocument
      oDoc.Range.Font.Color = WdColor.wdColorBlack


      oDoc.Save()
      oDoc.Close()
      oDoc = Nothing
      oWord.Quit()
      oWord = Nothing
Posted

1 solution

To add a picture in the location of current selection you can use InlineShapes.AddPicture[^]. Something like:
VB
oWord.Selection.InlineShapes.AddPicture( _
                  FileName := "C:\somedir\somefile.jpg", _
                  LinkToFile := False, _
                  SaveWithDocument:= True)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900