1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
'Pour la classe Registry
Imports Microsoft.Win32
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents btnLancerWord As System.Windows.Forms.Button
Friend WithEvents txtNom As System.Windows.Forms.TextBox
Friend WithEvents txtAdresse As System.Windows.Forms.TextBox
Friend WithEvents txtCP As System.Windows.Forms.TextBox
Friend WithEvents txtVille As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnLancerWord = New System.Windows.Forms.Button()
Me.txtNom = New System.Windows.Forms.TextBox()
Me.txtAdresse = New System.Windows.Forms.TextBox()
Me.txtCP = New System.Windows.Forms.TextBox()
Me.txtVille = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'btnLancerWord
'
Me.btnLancerWord.Location = New System.Drawing.Point(144, 176)
Me.btnLancerWord.Name = "btnLancerWord"
Me.btnLancerWord.Size = New System.Drawing.Size(112, 24)
Me.btnLancerWord.TabIndex = 0
Me.btnLancerWord.Text = "Lancer Word"
'
'txtNom
'
Me.txtNom.Location = New System.Drawing.Point(144, 40)
Me.txtNom.Name = "txtNom"
Me.txtNom.Size = New System.Drawing.Size(248, 20)
Me.txtNom.TabIndex = 1
Me.txtNom.Text = ""
'
'txtAdresse
'
Me.txtAdresse.Location = New System.Drawing.Point(144, 72)
Me.txtAdresse.Name = "txtAdresse"
Me.txtAdresse.Size = New System.Drawing.Size(248, 20)
Me.txtAdresse.TabIndex = 2
Me.txtAdresse.Text = ""
'
'txtCP
'
Me.txtCP.Location = New System.Drawing.Point(144, 104)
Me.txtCP.Name = "txtCP"
Me.txtCP.Size = New System.Drawing.Size(72, 20)
Me.txtCP.TabIndex = 3
Me.txtCP.Text = ""
'
'txtVille
'
Me.txtVille.Location = New System.Drawing.Point(144, 136)
Me.txtVille.Name = "txtVille"
Me.txtVille.Size = New System.Drawing.Size(144, 20)
Me.txtVille.TabIndex = 4
Me.txtVille.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(32, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 16)
Me.Label1.TabIndex = 5
Me.Label1.Text = "Nom"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(32, 80)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(88, 16)
Me.Label2.TabIndex = 6
Me.Label2.Text = "Adresse"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(32, 112)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(96, 16)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Code postal"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(32, 144)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(104, 16)
Me.Label4.TabIndex = 8
Me.Label4.Text = "Ville"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(440, 238)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.txtVille, Me.txtCP, Me.txtAdresse, Me.txtNom, Me.btnLancerWord})
Me.Name = "Form1"
Me.Text = "Automation Office"
Me.ResumeLayout(False)
End Sub
#End Region
Private objWord As Word.Application
Private objDoc As Word.Document
Private Sub btnLancerWord_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnLancerWord.Click
Dim sDoc As String
If VerifierWord() = False Then
MsgBox("Word n'est pas installé sur ce poste")
Exit Sub
End If
objWord = New Word.Application()
objWord.Visible = True
' Les classes Path et Application doivent être qualifiées
' car elles existent dans l'espace de noms Word.
sDoc = System.IO.Path.GetDirectoryName( _
System.Windows.Forms.Application.ExecutablePath())
sDoc &= "\AutomationWord.doc"
objDoc = objWord.Documents.Open(sDoc)
RenseignerSignet(txtNom, "Nom")
RenseignerSignet(txtAdresse, "Adresse")
RenseignerSignet(txtCP, "CP")
RenseignerSignet(txtVille, "Ville")
End Sub
Private Sub RenseignerSignet(ByVal Controle As TextBox, ByVal NomSignet As String)
Dim objRange As Word.Range
objRange = objDoc.Bookmarks.Item(NomSignet).Range
With objRange
.Text = Controle.Text
.Select()
End With
objDoc.Bookmarks.Add(NomSignet, objWord.Selection.Range)
End Sub
Private Function VerifierWord() As Boolean
Dim rkCR As RegistryKey = Registry.ClassesRoot
Dim rkWD As RegistryKey = rkCR.OpenSubKey("Word.Application")
Return Not (rkWD Is Nothing)
rkWD.Close()
End Function
End Class |
Partager