Logicwurks Home Page

Links To Excel Code Examples

Tracing VBA Statements
Range/Wkb/Wks Variables
Add Grand Totals Using Ranges
Using Range Offset Property
Using Range Find Method
ConvertCellAddressToRange
Set Conditional Formatting
Union Of Ranges
Parse Range Strings
Delete Duplicate Rows
Delete Rows And Columns
Worksheet Variables
TypeName And TypeOf
Loop Through Worksheets
Loop Through Open Workbooks
Form Button Magic
Command Button Magic
Add Worksheets Dynamically
ImportExternalWorksheets
Find Last Row Or Column
Copy And Paste Special
Copy To Specific Cell Types
Range Copy With Filter
ExcelFileOpenSaveClose
ExcelFileOpenSaveCSV
Open An Excel File
Open An Excel File w/Params
Open An Excel File On Web
Save A Workbook
Save A Workbook Using mso
Clone A Workbook
Test If WEB URL Exists
Parse Using Split Command
Using Classes in Excel
TypeStatementStructures
Color Management
Convert Cell Color To RGB
Sort Methods 2003 - 2010
Sort Alpha/Numeric In ASCII
Search Using Match Function
Search Using Vlookup Function
Search Using Xlookup Function
Using Find Instead of Vlookup
Remove String Non-Printables
Auto_Open And Auto_Close
Initialize Form At Open
Edit Numerics In UserForm
Load Combo And List Boxes
Floating Sheet Combo Boxes
Advanced User Form Coding
Excel Events
Worksheet Change Events
Binary Search Of Array
Typecast Constants
Excel Error Handling
Handling Optional Parameters
Data Validation Drop Downs
Insert Data Validation Sub
Read A Text File w/Handle
Write A Text File w/Handle
Read a Binary File w/Handle
Update a Binary File w/Handle
Binary File Copy and Update
Read A Text Fiile w/Script
Text File Processing Examples
Test For Exists Or Open
Splash Screen
Dynamically Load Formulas
PaymentStreamsByDate
Date Examples
Date Find Same Days
Convert Month To Number
Initialize Arrays
Load Arrays Using Evaluate
ChartsAndGraphsVBA
Redim An Array
Reassign Button Action
Timer Functions
Legacy Calendar Control
Excel 2010 Date Picker
Date Picker Alternative
Generate Multiple Worksheets
Read Access Data Into Excel
Send Outlook Email w/Attach
Copy AutoFilters To Sheets
Export A Text File
Get Windows User Name
VBA Format Statement
Manipulate Files via VBA
Dynamically Load Images
Loop Through Worksheet Objects
Loop Through Form Objects
Loop Through Files with DIR
Active-X Checkboxes
Add Forms Checkboxes Dynam
Paste Pictures Into Excel
Copy Pictures Sheet To Sheet
Copy Pictures Sheet To Sheet
Create Forms Buttons With VBA
Extract Filename From Path
Convert R1C1 Format to A1
Special Cells Property
Insert Cell Comments

Links To Access Code Examples

DAO Versus ADODB
SearchVBACodeStrings
Interface Excel With Access
Create Form Manually
Create Recordset With AddNew
Multi-Select List Boxes
Update Field(s) In A Recordset
Update Excel Pivot From Access
Import A Tab Delimited File
Export Excel FileDialog
Create Excel Within Access
Open Excel Within Access
Open Excel OBJ From Access
Format Excel From Access
Control Excel via Access VBA
On Error Best Practices
Import Tab Delim w/WinAPI
Initialize Global Variables
Using TempVars For Globals
Access Error Handling
Loop Through Form Controls
Insert A Calendar Control
Create A Filtered Recordset
Populate Combo Boxes
Bookmarks And Forms
Combo Box Multiple Sources
Passing Form Objects
Create VBA SQL Statements
Create Dynamic Queries
Display File Images On A Form
Manipulate Files via VBA
Manipulate Files via Scripting
Number Subform Records
Reference Subform Objects
Parse Delimited Fields
Parameterized Queries (VBA)
Manipulating QueryDefs In VBA
FindFirst On Combined Keys
Dlookup Command
Dlookup In Form Datasheet
Execute SQL Delete Records
Commit Form To Table
Report With No Data
Reference Form Objects
DSNLess Connections To MySQL
Print Active Form Record
Count Records in Linked Tables
Delete Empty Tables
Open Linked SQL Tables

 

Making Check Boxes Behave Like Radio Buttons

Unlike radio buttons, check boxes don't cycle through with only one box being checked. Sometimes it is desirable to allow only a single check box while turning off all other check boxes in the same group. The code to accomplish that is shown below. Note that the Application.EnableEvents = False doesn't work for this type of control change.

Program Code

Option Explicit
Dim intCount As Integer

Private Sub CheckBox1_Click()
If intCount <> 0 Then
    Exit Sub
End If
intCount = 1
Me.CheckBox2.Value = False
Me.CheckBox3.Value = False
intCount = 0
End Sub

Private Sub CheckBox2_Click()
If intCount <> 0 Then
    Exit Sub
End If
intCount = 1
Me.CheckBox1.Value = False
Me.CheckBox3.Value = False
intCount = 0
End Sub

Private Sub CheckBox3_Click()
If intCount <> 0 Then
    Exit Sub
End If
intCount = 1
Me.CheckBox1.Value = False
Me.CheckBox2.Value = False
intCount = 0
End Sub

Creating And Manipulating Active-X Checkboxes

This code segment shows to to create, modify and access properties of Active-X Checkboxes.

Program Code

Option Explicit
' ***************************************************************
' Check To See The Type of Active-X OLE Object
' THIS FIRST SUB ONLY WORKS IN FORMS - NOT WORKSHEETS
' ***************************************************************

Sub ManipulateActiveXCheckboxes()
Dim wksCheckBoxes As Worksheet

Dim o As OLEObject

Set wksCheckBoxes = Sheets("Short Sleeve Attributes Page")

For Each o In wksCheckBoxes.OLEObjects
    If TypeOf o.Object Is MSForms.CheckBox Then
        o.Object.Value = False
    End If
Next o

End Sub

' ***************************************************************
' Other Manipulation Methods
' ***************************************************************
Option Explicit

Sub ManipulateActiveXCheckboxes()

Dim oleObj As OLEObject
Dim intCount As Integer
Dim sh As Worksheet
Dim s As Shape
Dim o As OLEObject
Set sh = ActiveSheet
Dim obj As OLEObject

Set oleObj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=Range("C10").Left, _
Top:=Range("C10").Top, Width:=108, Height:=19.5)

With oleObj.Object
    .Caption = "Click Me"
    .Font.Size = 10
    .Font.Italic = True
    .Font.Bold = True
    .Value = xlOff
End With

intCount = sh.OLEObjects.Count
Debug.Print "OLE Objects = " & intCount

For Each o In sh.OLEObjects
    If o.progID = "Forms.CheckBox.1" Then
        Debug.Print o.Name
        Debug.Print o.OLEType
        Debug.Print o.Object.Value
        Debug.Print o.Object.Caption
        o.Object.Caption = "Hello"
        o.Object.Value = xlOn
        Debug.Print o.Object.Caption
        Debug.Print o.Object.Value
        Debug.Print o.TopLeftCell.Address
    End If
Next o

Set sh = Nothing

End Sub