VBA Object!

If I add some VBA object in a word document (let's say a checkbox) how can I interact with it in my regular VB application? (Changing/reading its property) ??

nfuidsAsked:
Who is Participating?
 
xSinbadCommented:
An example from MS;

Dim i As Integer

Private Sub CommandButton1_Click()
    TextBox1.Text = "Value of " & ActiveControl.Name & " is " & ActiveControl.Value
End Sub

Private Sub UserForm_Initialize()
    CommandButton1.Caption = "Get value of current control"
    CommandButton1.AutoSize = True
    CommandButton1.TakeFocusOnClick = False
    CommandButton1.TabStop = False
   
    TextBox1.AutoSize = True
   
    For i = 0 To 10
        ComboBox1.AddItem "Choice " & (i + 1)

        ListBox1.AddItem "Selection " & (100 - i)
    Next i
   
    CheckBox1.TripleState = True
    ToggleButton1.TripleState = True
   
    TextBox2.Text = "Enter text here."
End Sub

0
 
xSinbadCommented:
Give the object a name like chkName then use the VBE to refernce it.
0
 
Richie_SimonettiIT OperationsCommented:
hearing... no so simple xSinbad
;)
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
nfuidsAuthor Commented:
I need some sample...
0
 
Richie_SimonettiIT OperationsCommented:
This code is used within vba, no outside in VB.
0
 
nfuidsAuthor Commented:
But how could I call Private Sub CommandButton1_Click() from my VB application??
0
 
Richie_SimonettiIT OperationsCommented:
That's what i mean....
0
 
xSinbadCommented:
Sorry about that I had just finished answering some questions in the Office area and my brain still hadnt swithced topics. You can use automation.

example;

Function AccessWordObject()
Dim objWD As Object
Dim strFlName As String

strFlName = FILE NAME
Set objWD = GetObject(, "Word.Application")

Set objWD = GetObject(strFlName)

   With objWD.Application
' ***********************************************
    ' Place you VBA code in here  
      .Application.Run "Macro.Function"

" ***********************************************
   End With

   Set objWD = Nothing

End Function
0
 
xSinbadCommented:
How are you going with this one nfuids ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.