J
Joda-oda via OfficeKB.com
Imports Office = Microsoft.Office.Core
Imports Word = Microsoft.Office.Interop.Word
Class Form1
Dim oWord As Word.Application
Dim myBar As Office.CommandBar
Public WithEvents myButton As Office.CommandBarButton
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.
EventArgs) Handles Me.Load
Call Loading_Context_Menu()
End Sub
Public Sub Loading_Context_Menu()
Try
oWord = GetObject(, "Word.Application")
oWord.CommandBars("TEXT").Reset()
myBar = oWord.CommandBars("TEXT")
If myBar IsNot Nothing Then
Dim TEXTControlCount As Integer = myBar.Controls.Count
myButton = CType(myBar.Controls.Add(Type:=Office.
MsoControlType.msoControlButton, Before:=TEXTControlCount, Temporary:=True),
Office.CommandBarButton)
With myButton
.Caption = "Send to my Application"
.Tag = "Send to my Application"
.FaceId = 100
End With
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub myButton_Click(ByVal Ctrl As Microsoft.Office.Core.
CommandBarButton, ByRef CancelDefault As Boolean) Handles myButton.Click
TextBox1.Text = oWord.Selection.Text '<----- Doesn't Work
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.
Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
oWord.CommandBars("TEXT").Reset()
End Sub
End Class
Imports Word = Microsoft.Office.Interop.Word
Class Form1
Dim oWord As Word.Application
Dim myBar As Office.CommandBar
Public WithEvents myButton As Office.CommandBarButton
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.
EventArgs) Handles Me.Load
Call Loading_Context_Menu()
End Sub
Public Sub Loading_Context_Menu()
Try
oWord = GetObject(, "Word.Application")
oWord.CommandBars("TEXT").Reset()
myBar = oWord.CommandBars("TEXT")
If myBar IsNot Nothing Then
Dim TEXTControlCount As Integer = myBar.Controls.Count
myButton = CType(myBar.Controls.Add(Type:=Office.
MsoControlType.msoControlButton, Before:=TEXTControlCount, Temporary:=True),
Office.CommandBarButton)
With myButton
.Caption = "Send to my Application"
.Tag = "Send to my Application"
.FaceId = 100
End With
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub myButton_Click(ByVal Ctrl As Microsoft.Office.Core.
CommandBarButton, ByRef CancelDefault As Boolean) Handles myButton.Click
TextBox1.Text = oWord.Selection.Text '<----- Doesn't Work
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.
Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
oWord.CommandBars("TEXT").Reset()
End Sub
End Class