Results 1 to 3 of 3

Thread: {RESOLVED} Checking a checkbox in word from within VB.Net

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    17

    Resolved {RESOLVED} Checking a checkbox in word from within VB.Net

    Hi, I have a word template and I'm able to insert text to it from within a VB app but I have a check box in word I'm trying to check but I dont' know how to go about it. Here's the code I got from vbforums (works with regular texts) but can't figure out how to check boxes.. any help please? thanks

    VB Code:
    1. Private Sub GenerateDoc()
    2.         Dim app As Word.Application
    3.         Dim doc As Word.Document
    4.         Dim bookmark As Word.Bookmark
    5.         Dim bookmarkValue As Object
    6.         Dim outputFileName As String
    7.         Dim fileName As String = "C:\Documents and Settings\me\My Documents\temp.doc"
    8.  
    9.         'create the application object
    10.         app = CreateObject("Word.Application")
    11.         'open the document
    12.         app.Documents.Open(fileName)
    13.         'copy and save as
    14.         doc = app.ActiveDocument
    15.         outputFileName = "C:\Documents and Settings\me\My Documents\temm" & Format(Today, "yyyymmdd") & ".doc"
    16.         doc.SaveAs(outputFileName)
    17.  
    18.         'iterate through the bookmarks and find the matching field values
    19.         For Each bookmark In doc.Bookmarks
    20.             'If bookmark.Name = "Check1" Then
    21.             '    bookmark.Start = 1
    22.             'Else
    23.  
    24.                 'get the value for the bookmark
    25.                 bookmarkValue = TextBox2.Text
    26.                 If IsNothing(bookmarkValue) Then
    27.                     MsgBox("Couldn't find " & bookmark.Name)
    28.                 End If
    29.                 'get the value for the bookmark
    30.                 bookmark.Range.Text = TextBox2.Text
    31.             'End If
    32.         Next
    33.         doc.Close()
    34.  
    35.     End Sub
    Last edited by Makavelli; Aug 5th, 2005 at 12:33 PM. Reason: Resolved

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Checking a checkbox in word from within VB.Net

    A Word Checkbox can be of at least 2 different types, each requiring its own logic in order to access is value. Did you add a ActiveX control checkbox or a Word Formscheckbox?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    17

    Re: Checking a checkbox in word from within VB.Net

    I added a word formscheckbox from the Forms toolbar in MS word

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width