PC Review


Reply
Thread Tools Rate Thread

Disable Optionbutton Control

 
 
badgerzz1
Guest
Posts: n/a
 
      2nd Jun 2008
I have option buttons on an excel worksheet which are disabled when certain
tasks on the sheet are completed. I can enable and disable them OK but when
they are disabled there are "greyed out" - this results in poor quality
printing.

Is there a way to disable the control while retaining the text and
background properties of the control? i.e. black text


 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      2nd Jun 2008
Hi Badgerzz1,

In the Workbook's ThisWorkbook
module, paste:

'=============>>
Option Explicit

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Call EnableDisable(True)
Application.OnTime Now, "AfterPrint"
End Sub
'<<=============

This is event code and should be pasted
into the worksheets's code module (not a
standard module and not the workbook's
ThisWorkbook module):

Right-click the worksheet's tab |
Select 'View Code' from the menu
Paste the code
Alt-F11 to return to Excel.


In a standard module, paste:

'=============>>
Option Explicit

'-------------->>
Public Sub AfterPrint()
Call EnableDisable(False)
End Sub

'-------------->>
Public Sub EnableDisable(blEnable As Boolean)
Dim WB As Workbook
Dim SH As Worksheet
Dim arr As Variant
Dim oleObj As OLEObject
Dim i As Long

Set WB = Workbooks("Book3")
Set SH = WB.Sheets("Sheet1")

For Each oleObj In SH.OLEObjects
With oleObj
If TypeOf .Object Is MSForms.OptionButton Then
.Object.Enabled = blEnable
End If
End With
Next oleObj

End Sub
'<<=============



---
Regards.
Norman


"badgerzz1" <(E-Mail Removed)> wrote in message
news:90A9B3BA-2510-4B2D-A64E-(E-Mail Removed)...
>I have option buttons on an excel worksheet which are disabled when certain
> tasks on the sheet are completed. I can enable and disable them OK but
> when
> they are disabled there are "greyed out" - this results in poor quality
> printing.
>
> Is there a way to disable the control while retaining the text and
> background properties of the control? i.e. black text
>
>


 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      2nd Jun 2008
Hi Badgerzz1,

Having re-read your requirement, replace
the sugested code witrh the following
version:

In the workbook's Thisworkbook
module, paste:

'=============>>
Option Explicit

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim SH As Worksheet
Dim oleObj As OLEObject
Dim i As Long

Set SH = Me.Sheets(shName)
Erase arr

For Each oleObj In SH.OLEObjects
With oleObj
If TypeOf .Object Is MSForms.OptionButton Then
If .Object.Enabled = False Then
i = i + 1
ReDim Preserve arr(1 To i)
arr(i) = .Name
End If
End If
End With
Next oleObj

Call EnableDisable(True)
Application.OnTime Now, "AfterPrint"
End Sub
'<<=============

In a standard module, at the head of the
module, and before any other procedures,
paste the foling code:

'=============>>
Option Explicit
Public Const shName As String = "Sheet1" '<<==== CHANGE
Public arr() As String

'-------------->>
Public Sub AfterPrint()
Call EnableDisable(False)
End Sub

'-------------->>
Public Sub EnableDisable(blEnable As Boolean)
Dim WB As Workbook
Dim SH As Worksheet
Dim oleObj As OLEObject
Dim i As Long

Set WB = ThisWorkbook
Set SH = WB.Sheets(shName)

For i = LBound(arr) To UBound(arr)
With SH.OLEObjects(arr(i))
.Object.Enabled = blEnable
End With
Next i

End Sub
'<<=============


---
Regards.
Norman
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable optionbutton Cimjet Microsoft Excel Programming 3 10th Jun 2011 01:43 PM
Retrieving OptionButton Control Value Jay Microsoft Excel Programming 2 15th Feb 2008 04:23 PM
Disable or lock a control based on the value of another control =?Utf-8?B?TWFyayBCYWtlcg==?= Microsoft Access Forms 3 13th Mar 2007 02:21 AM
Disable control on exit - Can't disable control that has focus... =?Utf-8?B?SkJIYW5zZW4=?= Microsoft Access Form Coding 2 19th Feb 2007 07:19 PM
Control OptionButton =?Utf-8?B?b2tlYW5hbWFu?= Microsoft Word Document Management 1 5th Aug 2006 10:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:50 AM.