Solved

Change Word Option Button using Visual Basic 6

Posted on 2014-03-20
2
639 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
Comment Utility
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
Comment Utility
Worked a treat!

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

8 Experts available now in Live!

Get 1:1 Help Now