Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 660
  • Last Modified:

Change Word Option Button using Visual Basic 6

Hello,

I am looking to change the value for a word Option Button using the Word Object Model from within a Visual Basic 6 application.
0
dwknight
Asked:
dwknight
1 Solution
 
GrahamSkanRetiredCommented:
If the control is on a document, you can use something like this. The code uses early binding, so needs a reference to the Microsoft Word Object Library.
Sub ActiveXButton()
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    Dim bNewInstance As Boolean
    
    'try to use existing instance of application
    On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
    On Error GoTo 0
        
    If wdApp Is Nothing Then
        'no existing application, so create a new one
        Set wdApp = CreateObject("Word.Application")
        bNewInstance = True
    End If
    wdApp.Visible = True

    Set wdDoc = wdApp.Documents.Open("C:\MyFolder\Mydoc.doc")
    
    With wdDoc
        .OptionButton1.Value = True
        .Close wdSaveChanges
    End With
    
    'close application if specially created for this code
    If bNewInstance Then
        wdApp.Quit
    End If
End Sub

Open in new window

0
 
dwknightAuthor Commented:
Worked a treat!

Truly worth your weight in gold - well 500 points at least!...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now