Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Shift down macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Staroslav - 26 Apr 2005 09:39 GMT
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!
Anand.V.V.N - 26 Apr 2005 12:13 GMT
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

> 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!
Staroslav - 26 Apr 2005 12:48 GMT
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

> Hi Staroslav,
>
[quoted text clipped - 10 lines]
> > right key terms. Can's seem to find what I need.
> > Thanks!
Helmut Weber - 26 Apr 2005 13:38 GMT
Hi Staroslav,

there is a new articel by Jay Freedman:

http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm

containing a section on:
--- Making toggle macros

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Staroslav - 26 Apr 2005 14:05 GMT
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?

> Hi Staroslav,
>
[quoted text clipped - 9 lines]
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
Helmut Weber - 26 Apr 2005 14:56 GMT
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
Staroslav - 30 Jun 2005 14:23 GMT
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

Signature

Greetings from Moscow, Russia

> Hi Staroslav
>
[quoted text clipped - 27 lines]
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.