![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
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
|
|
#2
|
|||
|
|||
|
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey Dim isAnjing As Boolean Select Case ActiveSheet.CheckBoxes("CheckAnjing").Value Case 1: isAnjing = True Case -4146: isAnjing = False End Select lbl_Exit: Exit Sub End Sub |
|
|
|
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 |
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 |