Minggu, 15 April 2012

Re: [ExcelVBA] SOLUTION: Using the Shell function in VBA

 


Thanks Steve!

... And I agree about the frustration!...

Lisa

Sent: Fri, Apr 13, 2012 10:14 pm
Subject: [ExcelVBA] SOLUTION: Using the Shell function in VBA

-- 1z@... wrote:
It's great to see people get back with solutions Steve.
Thanks Lisa. I'm always frustrated when Group posters provide piecemeal
olutions, then don't think to either summarize them or put them in the Files
rea to circumvent the ever present "That's been discussed countless times
efore on this Group, please Search the Archives." manditory responses....

er.... what is the 3... ? Lisa
OOPS! Dunno' wa happen' there... Here 'tiz..
Using Shell in VBA SOLUTION:
I dug a bit more and found that adding the full name (mode.com) as well as
roviding a receptacle for the Shell return value did the trick.
Except ... VBA continues before it finishes setting the port parameters (and
ould actually be used) (asynchronous), so there must either be a delay before
OPENing" the port. This is usually not a problem if this is in the
penWorkbook Sub.
Or, you can use some other Kernel32 functions (ShellAndWait on the web), to
orce VBA to wait until it finishes.
This applies to any DOS command, not just Mode and the parameter string would
e the appropriate parameters for that command.
Do this:
Dim RetVal as Long
RetVal = Shell(Environ("comspec") + " /c mode.com Com4:9600,n,8,2", 3)
The string in " /c ... ,2" can also be assembled in a port setup procedure
llowing a user to select the parameters. This works on real serial ports and
SB with an external serial adapter.
The 3 is how the DOS window will be handled and is found in VBA Help, or on the
eb (I used 3 to make sure I saw (the flash) that it occurred), but:
vbHide 0 Window is hidden and focus is passed to the hidden window.
The vbHide constant is not applicable on Macintosh platforms.
vbNormalFocus 1 Window has focus and is restored to its original size and
osition.
vbMinimizedFocus 2 Window is displayed as an icon with focus.
vbMaximizedFocus 3 Window is maximized with focus.
vbNormalNoFocus 4 Window is restored to its most recent size and position. The
urrently active window remains active.
vbMinimizedNoFocus 6 Window is displayed as an icon. The currently active window
emains active.

Enjoy, Steve N.
o typos seen...

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar