Merci à tous.j'ai fait des recherches sur le site de microsoft et j'ai trouvé une réponse.
pour que ce code fonctionne, il faut d'abord aller dans le menu de visual studio(moi j'ai le 12) - projet- ajouter une reférence- une sorte de menu contextuel s'ouvre ;appuyez sur COM et cochez " [B][I][U]MIcrosoft word 12.0 object library/U/I/B" (pour certains le 12.0 peut être 14.0 ou autre.je l'ai même testé avec word 2007 ça marche parfaitement maispas proprement avec WORD 2010
Imports Word = Microsoft.Office.Interop.Word
Public Class historic
'note Private Sub PublipostageNoteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PublipostageNoteToolStripMenuItem.Click Dim oWord As Word.Application Dim oDoc As Word.Document
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
'Start Word and open the document template. oWord = CreateObject("Word.Application") oWord.Visible = True oDoc = oWord.Documents.Add Try 'Insertion de paragraphes. oPara1 = oDoc.Content.Paragraphs.Add oPara1.Range.Text = "MINISTERE AUPRES DU PREMIER MINISTRE " oPara1.Range.Font.Bold = True oPara1.Format.SpaceAfter = 2 '4 pt spacing after paragraph. oPara1.Range.InsertParagraphAfter()
pied de page Try oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True 'ce Footers en gras vous pouvez le changer en Headers et il de vient un haut de page With oDoc.Sections(1).[B]Footers/B(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
'note Private Sub PublipostageNoteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PublipostageNoteToolStripMenuItem.Click Dim oWord As Word.Application Dim oDoc As Word.Document
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
'Start Word and open the document template. oWord = CreateObject("Word.Application") oWord.Visible = True oDoc = oWord.Documents.Add Try 'Insertion de paragraphes. oPara1 = oDoc.Content.Paragraphs.Add oPara1.Range.Text = "MINISTERE AUPRES DU PREMIER MINISTRE " oPara1.Range.Font.Bold = True oPara1.Format.SpaceAfter = 2 '4 pt spacing after paragraph. oPara1.Range.InsertParagraphAfter()
Catch ex As Exception MsgBox(ex.ToString) End Try ' pied de page Try oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True 'ce Footers en gras vous pouvez le changer en Headers et il de vient un haut de page With oDoc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range