Solved

Change Word Option Button using Visual Basic 6

Posted on 2014-03-20
2
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Six Sigma Control Plans
Suggested Courses

622 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