Solved

Change Word Option Button using Visual Basic 6

Posted on 2014-03-20
2
641 Views
Last Modified: 2014-03-21
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
Comment
Question by:dwknight
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39944482
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
 

Author Closing Comment

by:dwknight
ID: 39944716
Worked a treat!

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now