Launching the Windows Calculator via vb, how? (Not the toolbar customize one, just actual vb code?)

  • Thread starter Thread starter Claus Busch
  • Start date Start date
C

Claus Busch

Hi,

Am Thu, 13 Jun 2013 04:13:31 -0500 schrieb StargateFan:
I found code to supposedly do this but I haven't gotten it to work. I
have this in my commandbar macros lineup:

***************************
Sub Launch_Windows_CALCULATOR()
' from: http://www.mrexcel.com/archive/VBA/17001.html
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1) ' The "1" is a
position upper left of the screen?, JSW
End Sub
***************************

the path for the calculator is wrong. Try:
RetVal = Shell("C:\Windows\System32\calc.exe", 1)


Regards
Claus Busch
 
Hi again,

Am Thu, 13 Jun 2013 04:13:31 -0500 schrieb StargateFan:
Since the QAT is so limited, and although I already have the Windows
calculator there, really need to launch the Windows calculator from an
XL sheet in a floating commandbar that then at least is available in
XL10 even if plasted to the ribbon.

or try:
Application.ActivateMicrosoftApp Index:=0


Regards
Claus Busch
 
Since the QAT is so limited, and although I already have the Windows
calculator there, really need to launch the Windows calculator from an
XL sheet in a floating commandbar that then at least is available in
XL10 even if plasted to the ribbon.

I found code to supposedly do this but I haven't gotten it to work. I
have this in my commandbar macros lineup:

***************************
Sub Launch_Windows_CALCULATOR()
' from: http://www.mrexcel.com/archive/VBA/17001.html
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1) ' The "1" is a
position upper left of the screen?, JSW
End Sub
***************************

The faceid icon I use is #283 for the calculator image.

Thx.
 
Claus said:
Am Thu, 13 Jun 2013 04:13:31 -0500 schrieb StargateFan:


the path for the calculator is wrong. Try:
RetVal = Shell("C:\Windows\System32\calc.exe", 1)

The path shouldn't be needed at all:

RetVal = Shell("calc", 1)

Another option is the ShellExecute API:

Public Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1

RetVal = ShellExecute(0, "", "calc", "", "", SW_SHOWNORMAL)
 
Hi,

Am Thu, 13 Jun 2013 04:13:31 -0500 schrieb StargateFan:


the path for the calculator is wrong. Try:
RetVal = Shell("C:\Windows\System32\calc.exe", 1)


Regards
Claus Busch

<lol> Oh, that was silly of me. Thanks for this! <g>
 
n Thu, 13 Jun 2013 14:22:09 +0000 (UTC), "Auric__"
The path shouldn't be needed at all:

RetVal = Shell("calc", 1)

Another option is the ShellExecute API:

Public Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1

RetVal = ShellExecute(0, "", "calc", "", "", SW_SHOWNORMAL)

Perfect, I'll give this a try at work later today. I'll report back.
 
I said:
The path shouldn't be needed at all:

RetVal = Shell("calc", 1)

Let me clarify this bit: the path isn't needed for apps in the search path;
Windows can find those without further assistance. If it's not in the search
path, the full path to the program is indeed required.
 
In message <[email protected]> of Thu, 13 Jun 2013 10:27:02
in microsoft.public.excel.programming, Claus Busch <claus_busch@t-
online.de> writes
Hi again,

Am Thu, 13 Jun 2013 04:13:31 -0500 schrieb StargateFan:

What is "the QAT"?
or try:
Application.ActivateMicrosoftApp Index:=0

Where did you find that 0?

In 2003 help, named constants have the following values:
?xlMicrosoftWord
1
?xlMicrosoftPowerPoint
2
?xlMicrosoftMail
3
?xlMicrosoftAccess
4
?xlMicrosoftFoxPro
5
?xlMicrosoftProject
6
?xlMicrosoftSchedulePlus
7

8 and -2 gave me "Method 'ActivateMicrosoftApp' of object '_Application'
failed

-1 gave a more interesting "Run-time error '1004':
Cannot run 'SOL.EXE'. The program or one of its components is damaged or
missing.
I do not have solitaire on my Vista system.
Application.ActivateMicrosoftApp Index:=xlMicrosoftWord
starts Word. I infer the other named constants also work.

<http://www.office-archive.com/2-excel/822184fb6e870371.htm> covers both
0 and -1.

Undocumented Behavior is wonderful. ;)
 
Hi Walter,

Am Sat, 15 Jun 2013 08:33:51 +0100 schrieb Walter Briscoe:
What is "the QAT"?

the QAT is the Quick Access Toolbar. A feature since xl2007
Where did you find that 0?

I recorded a macro while starting calculator from excel


Regards
Claus Busch
 
Let me clarify this bit: the path isn't needed for apps in the search path;
Windows can find those without further assistance. If it's not in the search
path, the full path to the program is indeed required.

Well, that did work with the path. I actually figured that you were
talking about things like app in the system32 directory. I'm guessing
"shell" replaces an actual path (?). Whatever the case may be, this
did, indeed, work without the path to the Win calculator. Most kewl.

Thx.
 
StargateFan said:
Well, that did work with the path. I actually figured that you were
talking about things like app in the system32 directory. I'm guessing
"shell" replaces an actual path (?).

No, the search path is an environment variable that tells Windows (or Unix-
like systems, DOS, or OS/2) "there are programss in this set of directories
that can be run from anywhere without needing to enter the full path." See
here:

http://en.wikipedia.org/wiki/PATH_(variable)

Entering the full path will always work, as long as the program exists -- the
search path just makes it unnecessary. It dates back to text-mode operating
systems, where typing in (for example) "edit" is easier and less error-prone
than "C:\DOS\edit".
 
Back
Top