--- 1z@... wrote:
> It's great to see people get back with solutions Steve.
Thanks Lisa. I'm always frustrated when Group posters provide piecemeal solutions, then don't think to either summarize them or put them in the Files area to circumvent the ever present "That's been discussed countless times before 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 Providing a receptacle for the Shell return value did the trick.
Except ... VBA continues before it finishes setting the port parameters (and would 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 OpenWorkbook Sub.
Or, you can use some other Kernel32 functions (ShellAndWait on the web), to force VBA to wait until it finishes.
This applies to any DOS command, not just Mode and the parameter string would be 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 allowing a user to select the parameters. This works on real serial ports and USB with an external serial adapter.
The 3 is how the DOS window will be handled and is found in VBA Help, or on the web (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 position.
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 currently active window remains active.
vbMinimizedNoFocus 6 Window is displayed as an icon. The currently active window remains active.
Enjoy, Steve N.
No typos seen...
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