Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default How to stop a macro at a Shell line.

Hi,
The following macro run until the language inside the control panel has not
been set to english. The problem I have is that "Shell Cmdl$, vbNormalFocus"
show a box but the macro run during that time. If the language is not set to
english before the macro start, Shell Cmdl will be shown 2 times (instead of
one) even if the language is set to english when the first box is shown. What
happens is that before the user choose the value (first time) "Shell ...",
the macro run and the new parameters are set to old value. Any idea?
Thanks!
Alex
Sub test()
512 = GetUserDefaultLCID()

iRet1 = GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE, lpLCDataVar, 0)
Symbol = String$(iRet1, 0)
iRet2 = GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE, Symbol, iRet1)
'GetLocaleInfo(Locale, LOCALE_SDATE, Symbol, iRet1)
pos = InStr(Symbol, Chr$(0))
If pos 0 Then
Symbol = Left$(Symbol, pos - 1)
sLang = Symbol
End If
If sLang < "English" Then
MsgBox ("The regional settings must be English." & Chr(10) &
"Your currently setting are " & sLang & ". Please select English in the next
box")
Cmdl = "rundll32.exe shell32.dll,Control_RunDLL intl.cpl" + ",,5"
Shell Cmdl$, vbNormalFocus
GoTo 512
End If
End Sub
--
Alex St-Pierre
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to stop a macro at a Shell line.


Shell is asynchronous.

http://support.microsoft.com/kb/147392/en-us
XL: How to Force Macro Code to Wait for Outside Procedure

http://support.microsoft.com/kb/129796/en-us
HOWTO: 32-Bit App Can Determine When a Shelled Process Ends




--
Regards,
Tom Ogilvy

"Alex St-Pierre" wrote in message
...
Hi,
The following macro run until the language inside the control panel has
not
been set to english. The problem I have is that "Shell Cmdl$,
vbNormalFocus"
show a box but the macro run during that time. If the language is not set
to
english before the macro start, Shell Cmdl will be shown 2 times (instead
of
one) even if the language is set to english when the first box is shown.
What
happens is that before the user choose the value (first time) "Shell ...",
the macro run and the new parameters are set to old value. Any idea?
Thanks!
Alex
Sub test()
512 = GetUserDefaultLCID()

iRet1 = GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE, lpLCDataVar, 0)
Symbol = String$(iRet1, 0)
iRet2 = GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE, Symbol, iRet1)
'GetLocaleInfo(Locale, LOCALE_SDATE, Symbol, iRet1)
pos = InStr(Symbol, Chr$(0))
If pos 0 Then
Symbol = Left$(Symbol, pos - 1)
sLang = Symbol
End If
If sLang < "English" Then
MsgBox ("The regional settings must be English." & Chr(10) &
"Your currently setting are " & sLang & ". Please select English in the
next
box")
Cmdl = "rundll32.exe shell32.dll,Control_RunDLL intl.cpl" +
",,5"
Shell Cmdl$, vbNormalFocus
GoTo 512
End If
End Sub
--
Alex St-Pierre



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default How to stop a macro at a Shell line.

Thank Tom!
Using the second link, I modify one line (program executed) and all works!!
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

' Initialize the STARTUPINFO structu
start.cb = Len(start)

' Start the shelled application:
Ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

' Wait for the shelled application to finish:
Ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, Ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = Ret&
End Function

Sub Form_Click()
Dim retval As Long
'retval = ExecCmd("notepad.exe")
retval = ExecCmd("rundll32.exe shell32.dll,Control_RunDLL intl.cpl" +
",,5")
MsgBox "Process Finished, Exit Code " & retval
End Sub
--
Alex St-Pierre


"Tom Ogilvy" wrote:


Shell is asynchronous.

http://support.microsoft.com/kb/147392/en-us
XL: How to Force Macro Code to Wait for Outside Procedure

http://support.microsoft.com/kb/129796/en-us
HOWTO: 32-Bit App Can Determine When a Shelled Process Ends




--
Regards,
Tom Ogilvy

"Alex St-Pierre" wrote in message
...
Hi,
The following macro run until the language inside the control panel has
not
been set to english. The problem I have is that "Shell Cmdl$,
vbNormalFocus"
show a box but the macro run during that time. If the language is not set
to
english before the macro start, Shell Cmdl will be shown 2 times (instead
of
one) even if the language is set to english when the first box is shown.
What
happens is that before the user choose the value (first time) "Shell ...",
the macro run and the new parameters are set to old value. Any idea?
Thanks!
Alex
Sub test()
512 = GetUserDefaultLCID()

iRet1 = GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE, lpLCDataVar, 0)
Symbol = String$(iRet1, 0)
iRet2 = GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE, Symbol, iRet1)
'GetLocaleInfo(Locale, LOCALE_SDATE, Symbol, iRet1)
pos = InStr(Symbol, Chr$(0))
If pos 0 Then
Symbol = Left$(Symbol, pos - 1)
sLang = Symbol
End If
If sLang < "English" Then
MsgBox ("The regional settings must be English." & Chr(10) &
"Your currently setting are " & sLang & ". Please select English in the
next
box")
Cmdl = "rundll32.exe shell32.dll,Control_RunDLL intl.cpl" +
",,5"
Shell Cmdl$, vbNormalFocus
GoTo 512
End If
End Sub
--
Alex St-Pierre




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I stop Series Line from Dropping to Zero joefish Excel Discussion (Misc queries) 0 April 7th 06 06:30 PM
how shell open AcroReader w/command line filename? Ian Elliott Excel Programming 2 October 17th 05 07:10 PM
Stop the line when 0 is reached Nigel Charts and Charting in Excel 3 October 14th 05 10:07 PM
Macro problem on, Yellowed line - previous line or next line. Ed Excel Programming 7 March 29th 05 09:37 PM
Commands at the line prompt using Shell cogent Excel Programming 2 April 27th 04 04:56 AM


All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"