PC Review


Reply
Thread Tools Rate Thread

activate/deactivate the scroll button by vba

 
 
MicrosoftNews
Guest
Posts: n/a
 
      30th Nov 2007
hi all,

i'm looking for a code to activate the scroll lock function by vba.

i need to have two buttons on a excel sheet. one to activate this function
and one to switch off this function.

can someone give me a hand ?

thanks in advance

achim

XL2003/WINXPHome


 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      1st Dec 2007
Don't know about a Scroll Lock function. Do you mean ScrollArea function
which limits the area that can be selected or scrolled into? If so then
create a button from the Control Toolbox toolbar (Not Forms toolbar) and
while in Design Mode (Design Mode is toggled on and off with a button that
looks like a blue set square with a ruler and pencil and it defaults to
Design On on when you create the button.)

Right click the button just created and select properties. Make a note of
the Name of the button (Top of list in dialog box). Click X to close dialog
box.

Right click button again and select View code and the VBA editor will open
with the following 2 lines:-

Private Sub CommandButton1_Click()

End Sub



Copy and the code below and paste in between the sub name and end sub.

Check the comments in green and edit code as required.

Close the VBA editor. (X with red background in top right corner )

Now every time you click the button it will toggle the ScrollArea on and off
and also it toggles the Caption on the button so that you only need one
button.

'Check command button name in properties
'and edit name if not CommandButton1
If ActiveSheet.CommandButton1.Caption = "Lock Scroll" Then
ActiveSheet.ScrollArea = "A1:K20"
'Edit range so it is within the ScrollArea
ActiveSheet.Range("A1").Select
ActiveSheet.CommandButton1.Caption = "Unlock Scroll"
Else
ActiveSheet.ScrollArea = ""
ActiveSheet.CommandButton1.Caption = "Lock Scroll"
'Edit range to select required cell when unlocked
ActiveSheet.Range("A1").Select
End If


--
Regards,

OssieMac


"MicrosoftNews" wrote:

> hi all,
>
> i'm looking for a code to activate the scroll lock function by vba.
>
> i need to have two buttons on a excel sheet. one to activate this function
> and one to switch off this function.
>
> can someone give me a hand ?
>
> thanks in advance
>
> achim
>
> XL2003/WINXPHome
>
>
>

 
Reply With Quote
 
MicrosoftNews
Guest
Posts: n/a
 
      1st Dec 2007
Hi Ossie,

I want to switch on and off the scroll led with the following code
-------------------------------------------------------------------------------------
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_OEM_SCROLL = &H91
Private Const KEYEVENTF_KEYUP = &H2
Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer

Sub SCROLL_aktiv() 'SCROLL-Lock aktivieren (falls deaktiviert)
If Not (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
keybd_event VK_OEM_SCROLL, 1, 0, 0
keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
End If
End Sub

Sub SCROLL_inaktiv() ' SCROLL-Lock deaktivieren (falls aktiviert)
If (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
keybd_event VK_OEM_SCROLL, 1, 0, 0
keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
End If
End Sub
----------------------------------------------------------------------------------------

with the scroll_aktiv procedure i can toggle between on and off. but it
should only switch on the led. with scroll_inaktiv i can't switch of the
led - and i don't know why

the following procedure for the num lock led works fine
------------------------------------------------------------------------------
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_NUMLOCK = &H90
Private Const KEYEVENTF_KEYUP = &H2
Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer

Sub NUM_TOGGLE()
' NUM-Lock drücken
' Zunächst niederdrücken und dann wieder loslassen
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End Sub

Sub NUM_aktiv() 'NUM-Lock aktivieren (falls deaktiviert)
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
End Sub

Sub NUM_inaktiv() ' NUM-Lock deaktivieren (falls aktiviert)
If (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
End Sub
------------------------------------------------------------------------------------
thanks for any help ..



"OssieMac" <(E-Mail Removed)> schrieb im Newsbeitrag
news:E81F0DBE-D816-44C7-8B65-(E-Mail Removed)...
> Don't know about a Scroll Lock function. Do you mean ScrollArea function
> which limits the area that can be selected or scrolled into? If so then
> create a button from the Control Toolbox toolbar (Not Forms toolbar) and
> while in Design Mode (Design Mode is toggled on and off with a button that
> looks like a blue set square with a ruler and pencil and it defaults to
> Design On on when you create the button.)
>
> Right click the button just created and select properties. Make a note of
> the Name of the button (Top of list in dialog box). Click X to close
> dialog
> box.
>
> Right click button again and select View code and the VBA editor will open
> with the following 2 lines:-
>
> Private Sub CommandButton1_Click()
>
> End Sub
>
>
>
> Copy and the code below and paste in between the sub name and end sub.
>
> Check the comments in green and edit code as required.
>
> Close the VBA editor. (X with red background in top right corner )
>
> Now every time you click the button it will toggle the ScrollArea on and
> off
> and also it toggles the Caption on the button so that you only need one
> button.
>
> 'Check command button name in properties
> 'and edit name if not CommandButton1
> If ActiveSheet.CommandButton1.Caption = "Lock Scroll" Then
> ActiveSheet.ScrollArea = "A1:K20"
> 'Edit range so it is within the ScrollArea
> ActiveSheet.Range("A1").Select
> ActiveSheet.CommandButton1.Caption = "Unlock Scroll"
> Else
> ActiveSheet.ScrollArea = ""
> ActiveSheet.CommandButton1.Caption = "Lock Scroll"
> 'Edit range to select required cell when unlocked
> ActiveSheet.Range("A1").Select
> End If
>
>
> --
> Regards,
>
> OssieMac
>
>
> "MicrosoftNews" wrote:
>
>> hi all,
>>
>> i'm looking for a code to activate the scroll lock function by vba.
>>
>> i need to have two buttons on a excel sheet. one to activate this
>> function
>> and one to switch off this function.
>>
>> can someone give me a hand ?
>>
>> thanks in advance
>>
>> achim
>>
>> XL2003/WINXPHome
>>
>>
>>



 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      1st Dec 2007
Hi again,

I totally misunderstood what you were trying to do and I can't help with
your problem
--
Regards,

OssieMac


"MicrosoftNews" wrote:

> Hi Ossie,
>
> I want to switch on and off the scroll led with the following code
> -------------------------------------------------------------------------------------
> Private Declare Sub keybd_event Lib "user32" ( _
> ByVal bVk As Byte, _
> ByVal bScan As Byte, _
> ByVal dwFlags As Long, _
> ByVal dwExtraInfo As Long)
> Private Const VK_OEM_SCROLL = &H91
> Private Const KEYEVENTF_KEYUP = &H2
> Declare Function GetKeyState Lib "user32.dll" ( _
> ByVal nVirtKey As Long) As Integer
>
> Sub SCROLL_aktiv() 'SCROLL-Lock aktivieren (falls deaktiviert)
> If Not (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
> keybd_event VK_OEM_SCROLL, 1, 0, 0
> keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
> End If
> End Sub
>
> Sub SCROLL_inaktiv() ' SCROLL-Lock deaktivieren (falls aktiviert)
> If (GetKeyState(vbKeyOEM_SCROLL) = 1) Then
> keybd_event VK_OEM_SCROLL, 1, 0, 0
> keybd_event VK_OEM_SCROLL, 1, KEYEVENTF_KEYUP, 0
> End If
> End Sub
> ----------------------------------------------------------------------------------------
>
> with the scroll_aktiv procedure i can toggle between on and off. but it
> should only switch on the led. with scroll_inaktiv i can't switch of the
> led - and i don't know why
>
> the following procedure for the num lock led works fine
> ------------------------------------------------------------------------------
> Private Declare Sub keybd_event Lib "user32" ( _
> ByVal bVk As Byte, _
> ByVal bScan As Byte, _
> ByVal dwFlags As Long, _
> ByVal dwExtraInfo As Long)
> Private Const VK_NUMLOCK = &H90
> Private Const KEYEVENTF_KEYUP = &H2
> Declare Function GetKeyState Lib "user32.dll" ( _
> ByVal nVirtKey As Long) As Integer
>
> Sub NUM_TOGGLE()
> ' NUM-Lock drücken
> ' Zunächst niederdrücken und dann wieder loslassen
> keybd_event VK_NUMLOCK, 1, 0, 0
> keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
> End Sub
>
> Sub NUM_aktiv() 'NUM-Lock aktivieren (falls deaktiviert)
> If Not (GetKeyState(vbKeyNumlock) = 1) Then
> keybd_event VK_NUMLOCK, 1, 0, 0
> keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
> End If
> End Sub
>
> Sub NUM_inaktiv() ' NUM-Lock deaktivieren (falls aktiviert)
> If (GetKeyState(vbKeyNumlock) = 1) Then
> keybd_event VK_NUMLOCK, 1, 0, 0
> keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
> End If
> End Sub
> ------------------------------------------------------------------------------------
> thanks for any help ..
>
>
>
> "OssieMac" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:E81F0DBE-D816-44C7-8B65-(E-Mail Removed)...
> > Don't know about a Scroll Lock function. Do you mean ScrollArea function
> > which limits the area that can be selected or scrolled into? If so then
> > create a button from the Control Toolbox toolbar (Not Forms toolbar) and
> > while in Design Mode (Design Mode is toggled on and off with a button that
> > looks like a blue set square with a ruler and pencil and it defaults to
> > Design On on when you create the button.)
> >
> > Right click the button just created and select properties. Make a note of
> > the Name of the button (Top of list in dialog box). Click X to close
> > dialog
> > box.
> >
> > Right click button again and select View code and the VBA editor will open
> > with the following 2 lines:-
> >
> > Private Sub CommandButton1_Click()
> >
> > End Sub
> >
> >
> >
> > Copy and the code below and paste in between the sub name and end sub.
> >
> > Check the comments in green and edit code as required.
> >
> > Close the VBA editor. (X with red background in top right corner )
> >
> > Now every time you click the button it will toggle the ScrollArea on and
> > off
> > and also it toggles the Caption on the button so that you only need one
> > button.
> >
> > 'Check command button name in properties
> > 'and edit name if not CommandButton1
> > If ActiveSheet.CommandButton1.Caption = "Lock Scroll" Then
> > ActiveSheet.ScrollArea = "A1:K20"
> > 'Edit range so it is within the ScrollArea
> > ActiveSheet.Range("A1").Select
> > ActiveSheet.CommandButton1.Caption = "Unlock Scroll"
> > Else
> > ActiveSheet.ScrollArea = ""
> > ActiveSheet.CommandButton1.Caption = "Lock Scroll"
> > 'Edit range to select required cell when unlocked
> > ActiveSheet.Range("A1").Select
> > End If
> >
> >
> > --
> > Regards,
> >
> > OssieMac
> >
> >
> > "MicrosoftNews" wrote:
> >
> >> hi all,
> >>
> >> i'm looking for a code to activate the scroll lock function by vba.
> >>
> >> i need to have two buttons on a excel sheet. one to activate this
> >> function
> >> and one to switch off this function.
> >>
> >> can someone give me a hand ?
> >>
> >> thanks in advance
> >>
> >> achim
> >>
> >> XL2003/WINXPHome
> >>
> >>
> >>

>
>
>

 
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
activate/deactivate button with macro at given condition arcq Microsoft Excel Programming 1 17th Mar 2005 05:35 AM
wifi activate/deactivate vhoward Microsoft Dot NET Compact Framework 1 24th Jan 2005 05:01 PM
AccessWeb API for App Activate/Deactivate kiln Microsoft Access VBA Modules 3 19th Dec 2004 03:23 AM
AccessWeb API for App Activate/Deactivate kiln Microsoft Access Form Coding 3 19th Dec 2004 03:23 AM
How to activate "double clic" on the scroll button Benoit Windows XP Drivers 0 12th Aug 2003 12:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:03 PM.