Shift down macro

S

Staroslav

How do you write a macro that does one set of commands if a shift (ctrl or
any other) button is pressed and another set of commands if it is not pressed?

I tried searching for examples on the web, but perhaps I am not using the
right key terms. Can's seem to find what I need.
Thanks!
 
A

Anand.V.V.N

Hi Staroslav,

In which event you are writing the code? Are you using this in a form by any
chance? If you can tell where you writing your macro it will be helpful to
suggest.


Anand
 
S

Staroslav

I am dealing with two environments: simple text and tables. I thought that
instead of having two or more macros that do essentially the same thing with
one or two variations it would be easier to have one, provided you can hold
Shift (or other) and click on a customized toolbar button to run it. So, that
is where the difficulty lies, I am not dealing with forms or command buttons.

Along this line, is there a way you can customize your toolbar buttons, so
that when you click once, it does one thing and when you click twice, it does
another?

Appreciate your help.
vs
 
S

Staroslav

Thanks Helmut,
I do make use of the toggle principle, but what I am asking is a toggle of a
slightly different character. When it is not possible to codify all of the
conditions, my decision is necessary. I am just trying to find ways to avoid
having my customized toolbar cluttered with buttons by employing mouse events
or button down events. Can it be done?
 
H

Helmut Weber

Hi Staroslav

google for GetKeyState.

A very simple example:

Private Declare Function GetKeyState Lib "user32"
(ByVal vKey As Long) As Integer
Function ShiftState() As Integer
Const VK_SHIFT = &H10
Const VK_CONTROL = &H11
ShiftState = (Abs(GetKeyState(VK_SHIFT) < 0) * 1) + _
(Abs(GetKeyState(VK_CONTROL) < 0) * 2)
End Function
---
Sub TestKeyState()
MsgBox ShiftState
' ctrl = 2
' shift ctrl = 3 usw.
End Sub

Example covering all by Thomas Gahler:

http://tinyurl.com/8buvg

Partly in German, but doesn't matter.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Staroslav

Helmut, thank you for your help. This is what I was looking for, but for the
life of me I cannot get it to work in a simple macro as the one below. How do
I intergrade your code so it would work? I tried everything I can think of,
but alas...

Sub CellUnderline()
'macro underlines a cell with a single 0.5pt width line if Shift key is down _
and 0.75pt if not

Selection.Cells(1).Select
With Selection.Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
'If Shift_Is_Down Then
.LineWidth = wdLineWidth050pt
'Else
.LineWidth = wdLineWidth075pt
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top