Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-10-2025, 01:44 AM
calinanix calinanix is offline Hide text with certain style in Word using form control checkboxes in Excel Windows 11 Hide text with certain style in Word using form control checkboxes in Excel Office 2021
Novice
Hide text with certain style in Word using form control checkboxes in Excel
 
Join Date: Sep 2025
Posts: 7
calinanix is on a distinguished road
Question Hide text with certain style in Word using form control checkboxes in Excel

Hello, this is my first post. I'm trying to build an Excel workbook which will generate a Word document using find and replace as well as checkbox-controlled conditional texts. I've figured out the F&R part, and now I'm struggling with the checkbox-controlled conditional text part.


The checkbox I'm using is the form controls checkbox, as the final product will be used by a lot of people, I thought it would be more user-friendly than to use ActiveX. However, the VBA code I tried can't seem to read the value of the checkboxes correctly. It keeps returning TRUE no matter the state of the checkboxes.


I'm a beginner in VBA so I'm not sure if I'm even employing the correct code to retrieve the checkboxes' values. I've tried using .Sheets(StrWkSht).Shapes("CheckAnjing").OLEFormat. Object.Value and .Sheets(StrWkSht).Shapes("CheckAnjing").ControlFor mat.Value, both with no avail.


isAnjing and isKucing true.png


Code provided below:


Code:
Sub HideStyles()

Application.ScreenUpdating = False
Dim xlApp As Object, xlWkBk As Object, StrWkBkNm As String, StrWkSht As String
StrWkBkNm = ThisWorkbook.Path & "\Macro Testing Ground.xlsm"
StrWkSht = "Sheet1"

Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then
  MsgBox "Can't start Excel.", vbExclamation
  Exit Sub
End If
On Error GoTo 0
With xlApp
    Set xlWkBk = .Workbooks.Open(StrWkBkNm, False, True)
    With xlWkBk
        Dim isAnjing As Boolean, isKucing As Boolean
        isAnjing = Not .Sheets(StrWkSht).Shapes("CheckAnjing").ControlFormat.Value
        isKucing = Not .Sheets(StrWkSht).Shapes("CheckKucing").ControlFormat.Value
    End With
End With

Dim wdDoc As Document

Set wdDoc = Documents.Open(ThisWorkbook.Path & "\Macro Testing Ground.docm")
With wdDoc
    .Styles("Strong").Font.Hidden = isAnjing
    .Styles("Emphasis").Font.Hidden = isKucing
End With
Set wdDoc = Nothing
Application.ScreenUpdating = True

End Sub
I would appreciate any help!
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use checkboxes in word to hide/show content learningtoword99 Word VBA 1 09-02-2025 12:57 AM
Hide text with certain style in Word using form control checkboxes in Excel Show and hide table rows with checkboxes in Word Eragon91 Word VBA 5 03-30-2024 07:55 PM
UserForm with checkboxes that hide/show bookmarked text in document dohertym Word VBA 4 05-16-2022 09:48 PM
Using Content Control Checkboxes to open associated excel files shaztastic Word VBA 5 08-26-2018 07:13 AM
Hide a combo box (form control), based on a cell value - Excel 2010 jaymudda Excel Programming 9 07-12-2015 10:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft