Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Microsoft.Office.Interop
- Public Class Form1
- Private WithEvents WordApplication As Word.Application
- Private WithEvents WordDocument As Word.Document
- Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
- WordDocument.Close()
- WordDocument = Nothing
- WordApplication.Visible = Nothing
- WordApplication = Nothing
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- InitComboBox()
- End Sub
- Private Sub InitComboBox()
- Me.ComboBox1.Items.Clear()
- For i As Integer = 0 To 10
- Me.ComboBox1.Items.Add("Signet_" & i)
- Next
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Me.OpenFileDialog1.FileName = String.Empty
- If Me.OpenFileDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
- Try
- If WordApplication Is Nothing Then
- 'Créer un nouveau application
- WordApplication = New Word.Application()
- WordApplication.Visible = True
- End If
- 'ouvrir le fichier
- WordDocument = WordApplication.Documents.Open(Me.OpenFileDialog1.FileName)
- Me.TextBox1.Text = Me.OpenFileDialog1.FileName
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End If
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim w As Word.Words = WordApplication.Selection.Words
- 'Create a rang from first word to last word
- Dim StartIndex As Integer = w.First.Start
- Dim StopIndex As Integer = w.Last.End
- Dim rng As Word.Range = WordDocument.Range(StartIndex, StopIndex)
- rng.Shading.BackgroundPatternColorIndex = Word.WdColorIndex.wdGray25
- rng.Bookmarks.Add(ComboBox1.Text)
- MsgBox("C'est bon")
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- Try
- WordDocument.Close()
- WordDocument = Nothing
- Catch ex As Exception
- End Try
- Try
- WordApplication.Visible = False
- WordApplication = Nothing
- Catch ex As Exception
- End Try
- End
- End Sub
- End Class
Add Comment
Please, Sign In to add comment