NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Imports Microsoft.Office.Interop

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oApp As Word.Application
Dim oSec As Word.Section
Dim oDoc As Word.Document

'Create a new document in Word
oApp = New Word.Application
oDoc = oApp.Documents.Add

'Make Word visible to examine the document
oApp.Visible = True

With oDoc

'=== SECTION 1 ==================================================

'Add two pages to the first section where the first page in the
'section has different headers and footers than the second page
oSec = .Sections(1)
oSec.PageSetup.DifferentFirstPageHeaderFooter = True
oSec.Range.InsertAfter("Text on Page 1 (Section 1)")
.Range(oSec.Range.End - 1).InsertBreak(Word.WdBreakType.wdPageBreak)
oSec.Range.InsertAfter("Text on Page 2 (Section 1)")

'Add the headers/footers for the first section (that contains two
'pages)

.Range(oSec.Range.End - 1).InsertBreak(Word.WdBreakType.wdPageBreak)
oApp.Selection.WholeStory()
oApp.Selection.Copy()
End With

Dim oApp2 As Word.Application
Dim oDoc2 As Word.Document
'Create a new document in Word
oApp2 = New Word.Application
oDoc2 = oApp.Documents.Add

'Make Word visible to examine the document
oApp2.Visible = True
With oDoc2

'=== SECTION 1 ==================================================

'Add two pages to the first section where the first page in the
'section has different headers and footers than the second page
oSec = .Sections(1)
oSec.PageSetup.DifferentFirstPageHeaderFooter = True
oSec.Range.InsertAfter("Text on Page 1 (Section 1)")
.Range(oSec.Range.End - 1).InsertBreak(Word.WdBreakType.wdPageBreak)
oSec.Range.InsertAfter("Text on Page 2 (Section 1)")

'Add the headers/footers for the first section (that contains two
'pages)
oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Text = "Page1 -- Section 1 First Page Header"
oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = "Page2 -- Section 1 Primary Header"
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Text = "Page1 -- Section 1 First Page Footer"
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = "Page2 -- Section 1 Primary Footer"

'=== SECTION 2 ==================================================

'Add a new section containing three pages where the first page in
'the section has different headers and footers than the other two
'pages
.Range(oSec.Range.End - 1).InsertBreak(Word.WdBreakType.wdSectionBreakNextPage)
oSec = .Sections(2)
oSec.PageSetup.DifferentFirstPageHeaderFooter = True
oSec.Range.InsertAfter("Text on Page 3 (Section 2)")
.Range(oSec.Range.End - 1).InsertBreak(Word.WdBreakType.wdPageBreak)
oSec.Range.InsertAfter("Text on Page 4 (Section 2)")
.Range(oSec.Range.End - 1).InsertBreak(Word.WdBreakType.wdPageBreak)
oSec.Range.InsertAfter("Text on Page 5 (Section 2)")

'Add the headers/footers for the second section (that contains
'three pages) -- notice that the second and third pages in this
'section will contain the primary header/footer
oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Text = _
"Page3 -- Section 2 First Page Header"
oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = False
oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = _
"Page4and5 -- Section 2 Primary Header"
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Text = _
"Page3 -- Section 2 First Page Footer"
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = False
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = _
"Page4and5 -- Section 2 Primary Footer"

.Range(oSec.Range.End - 1).InsertBreak(Word.WdBreakType.wdSectionBreakNextPage)
.Range(oSec.Range.End - 1).PasteAndFormat(Word.WdRecoveryType.wdPasteDefault)
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = False
oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Delete()

End With

End Sub
End Class
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.