Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DS DS is offline
external usenet poster
 
Posts: 117
Default ShellAndWait Query

Afternoon all,

I'm hitting a slight problem trying to get the ShellAndWait command running,
using the example on Ron DeBruin's site at: http://www.rondebruin.nl/zip.htm.
I've simply copied & pasted the code relating to "Zip The ActiveWorkbook" as
a starting point.

Specifically, I'm getting a "Sub Or Function Not Defined" error on the line
ShellAndWait ShellStr, vbHide

I'm wondering whether a specific required reference is not active, or
whether this function isn't available in this Excel version (2k). Replacing
ShellAndWait with Shell works ok, but I don't want VBA to continue running
until the zip operation is complete. Yes, I know I could simply insert an
Application.Wait, but this is gonna niggle at me until I know what's going on!

Any ideas appreciated, cheers!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ShellAndWait Query

I'm not familiar with the technique Ron used, so I can't help you debug it.
However, I have a different method for you to try and see if your code works
with it instead.

This is a method is different than the one from Ron that you are attempting
to use (it doesn't use a loop to perform its waiting operation) and is based
on code I have posted previously to the compiled VB newsgroups over the
years. The call statement from your own code to my ShellAndWait subroutine
is the same as for Ron's subroutine, so the only thing you will need to do
to make it work is to replace (comment out initially in case you want to go
back to it) all of Ron's ShellAndWait code and replace it with the code
below. If you hadn't already done so for Ron's routine, I would suggest
placing my code into a Module (Insert/Module from VBE's menu bar). As I said
before, call my ShellAndWait subroutine from within your own macro using the
exact **same** statement as you used to call Ron's version of ShellAndWait
(that is, you do **not** have to change your macro code at all to use the
code below).

Rick

'********** START OF MODULE CODE **********
Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF

Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim PID As Long
Dim hProcess As Long
If IsMissing(WindowState) Then WindowState = vbNormalFocus
PID = Shell(PathName, WindowState)
If PID = 0 Then
' Handle Error, Shell Didn't Work
MsgBox "Error executing Shell command!"
Else
hProcess = OpenProcess(SYNCHRONIZE, True, PID)
WaitForSingleObject hProcess, INFINITE
CloseHandle hProcess
End If
End Sub
'********** END OF MODULE CODE **********



"DS" wrote in message
...
Afternoon all,

I'm hitting a slight problem trying to get the ShellAndWait command
running,
using the example on Ron DeBruin's site at:
http://www.rondebruin.nl/zip.htm.
I've simply copied & pasted the code relating to "Zip The ActiveWorkbook"
as
a starting point.

Specifically, I'm getting a "Sub Or Function Not Defined" error on the
line
ShellAndWait ShellStr, vbHide

I'm wondering whether a specific required reference is not active, or
whether this function isn't available in this Excel version (2k).
Replacing
ShellAndWait with Shell works ok, but I don't want VBA to continue running
until the zip operation is complete. Yes, I know I could simply insert an
Application.Wait, but this is gonna niggle at me until I know what's going
on!

Any ideas appreciated, cheers!


  #3   Report Post  
Posted to microsoft.public.excel.programming
DS DS is offline
external usenet poster
 
Posts: 117
Default ShellAndWait Query

Many Thanks Rick, this has worked perfectly (as you knew it would!).

Much Appreciated,
DS

"Rick Rothstein (MVP - VB)" wrote:

I'm not familiar with the technique Ron used, so I can't help you debug it.
However, I have a different method for you to try and see if your code works
with it instead.

This is a method is different than the one from Ron that you are attempting
to use (it doesn't use a loop to perform its waiting operation) and is based
on code I have posted previously to the compiled VB newsgroups over the
years. The call statement from your own code to my ShellAndWait subroutine
is the same as for Ron's subroutine, so the only thing you will need to do
to make it work is to replace (comment out initially in case you want to go
back to it) all of Ron's ShellAndWait code and replace it with the code
below. If you hadn't already done so for Ron's routine, I would suggest
placing my code into a Module (Insert/Module from VBE's menu bar). As I said
before, call my ShellAndWait subroutine from within your own macro using the
exact **same** statement as you used to call Ron's version of ShellAndWait
(that is, you do **not** have to change your macro code at all to use the
code below).

Rick

'********** START OF MODULE CODE **********
Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF

Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim PID As Long
Dim hProcess As Long
If IsMissing(WindowState) Then WindowState = vbNormalFocus
PID = Shell(PathName, WindowState)
If PID = 0 Then
' Handle Error, Shell Didn't Work
MsgBox "Error executing Shell command!"
Else
hProcess = OpenProcess(SYNCHRONIZE, True, PID)
WaitForSingleObject hProcess, INFINITE
CloseHandle hProcess
End If
End Sub
'********** END OF MODULE CODE **********



"DS" wrote in message
...
Afternoon all,

I'm hitting a slight problem trying to get the ShellAndWait command
running,
using the example on Ron DeBruin's site at:
http://www.rondebruin.nl/zip.htm.
I've simply copied & pasted the code relating to "Zip The ActiveWorkbook"
as
a starting point.

Specifically, I'm getting a "Sub Or Function Not Defined" error on the
line
ShellAndWait ShellStr, vbHide

I'm wondering whether a specific required reference is not active, or
whether this function isn't available in this Excel version (2k).
Replacing
ShellAndWait with Shell works ok, but I don't want VBA to continue running
until the zip operation is complete. Yes, I know I could simply insert an
Application.Wait, but this is gonna niggle at me until I know what's going
on!

Any ideas appreciated, cheers!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default ShellAndWait Query

Hi DS

Note :
1) Don't forget to copy the Functions in a normal module.
2) Check out also the Unzip web page if you need examples for unzip a zip file.
3) Look on this page for all command line parameters that WinZip support.

http://www.rondebruin.nl/zip.htm#Functions

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DS" wrote in message ...
Many Thanks Rick, this has worked perfectly (as you knew it would!).

Much Appreciated,
DS

"Rick Rothstein (MVP - VB)" wrote:

I'm not familiar with the technique Ron used, so I can't help you debug it.
However, I have a different method for you to try and see if your code works
with it instead.

This is a method is different than the one from Ron that you are attempting
to use (it doesn't use a loop to perform its waiting operation) and is based
on code I have posted previously to the compiled VB newsgroups over the
years. The call statement from your own code to my ShellAndWait subroutine
is the same as for Ron's subroutine, so the only thing you will need to do
to make it work is to replace (comment out initially in case you want to go
back to it) all of Ron's ShellAndWait code and replace it with the code
below. If you hadn't already done so for Ron's routine, I would suggest
placing my code into a Module (Insert/Module from VBE's menu bar). As I said
before, call my ShellAndWait subroutine from within your own macro using the
exact **same** statement as you used to call Ron's version of ShellAndWait
(that is, you do **not** have to change your macro code at all to use the
code below).

Rick

'********** START OF MODULE CODE **********
Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF

Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim PID As Long
Dim hProcess As Long
If IsMissing(WindowState) Then WindowState = vbNormalFocus
PID = Shell(PathName, WindowState)
If PID = 0 Then
' Handle Error, Shell Didn't Work
MsgBox "Error executing Shell command!"
Else
hProcess = OpenProcess(SYNCHRONIZE, True, PID)
WaitForSingleObject hProcess, INFINITE
CloseHandle hProcess
End If
End Sub
'********** END OF MODULE CODE **********



"DS" wrote in message
...
Afternoon all,

I'm hitting a slight problem trying to get the ShellAndWait command
running,
using the example on Ron DeBruin's site at:
http://www.rondebruin.nl/zip.htm.
I've simply copied & pasted the code relating to "Zip The ActiveWorkbook"
as
a starting point.

Specifically, I'm getting a "Sub Or Function Not Defined" error on the
line
ShellAndWait ShellStr, vbHide

I'm wondering whether a specific required reference is not active, or
whether this function isn't available in this Excel version (2k).
Replacing
ShellAndWait with Shell works ok, but I don't want VBA to continue running
until the zip operation is complete. Yes, I know I could simply insert an
Application.Wait, but this is gonna niggle at me until I know what's going
on!

Any ideas appreciated, cheers!



  #5   Report Post  
Posted to microsoft.public.excel.programming
DS DS is offline
external usenet poster
 
Posts: 117
Default ShellAndWait Query

Morning Ron,

I just came by to update on this to clarify, and saw your reply.

Turns out it was all my fault. Surprised? =;-)

When I copied the ShellAndWait function, I mistyped the function name as
"ShelAndWait" - so when the main part was looking for "ShellAndWait", it
obviously couldn't find a function by that name...

How embarassed am I? Very. Just wanted to update so there was no chance of
besmirching your good name with my own astronomical incompetence!

Thanks for all the assistance (your site is a much-used resource!)
DS

"Ron de Bruin" wrote:

Hi DS

Note :
1) Don't forget to copy the Functions in a normal module.
2) Check out also the Unzip web page if you need examples for unzip a zip file.
3) Look on this page for all command line parameters that WinZip support.

http://www.rondebruin.nl/zip.htm#Functions

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DS" wrote in message ...
Many Thanks Rick, this has worked perfectly (as you knew it would!).

Much Appreciated,
DS

"Rick Rothstein (MVP - VB)" wrote:

I'm not familiar with the technique Ron used, so I can't help you debug it.
However, I have a different method for you to try and see if your code works
with it instead.

This is a method is different than the one from Ron that you are attempting
to use (it doesn't use a loop to perform its waiting operation) and is based
on code I have posted previously to the compiled VB newsgroups over the
years. The call statement from your own code to my ShellAndWait subroutine
is the same as for Ron's subroutine, so the only thing you will need to do
to make it work is to replace (comment out initially in case you want to go
back to it) all of Ron's ShellAndWait code and replace it with the code
below. If you hadn't already done so for Ron's routine, I would suggest
placing my code into a Module (Insert/Module from VBE's menu bar). As I said
before, call my ShellAndWait subroutine from within your own macro using the
exact **same** statement as you used to call Ron's version of ShellAndWait
(that is, you do **not** have to change your macro code at all to use the
code below).

Rick

'********** START OF MODULE CODE **********
Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF

Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim PID As Long
Dim hProcess As Long
If IsMissing(WindowState) Then WindowState = vbNormalFocus
PID = Shell(PathName, WindowState)
If PID = 0 Then
' Handle Error, Shell Didn't Work
MsgBox "Error executing Shell command!"
Else
hProcess = OpenProcess(SYNCHRONIZE, True, PID)
WaitForSingleObject hProcess, INFINITE
CloseHandle hProcess
End If
End Sub
'********** END OF MODULE CODE **********



"DS" wrote in message
...
Afternoon all,

I'm hitting a slight problem trying to get the ShellAndWait command
running,
using the example on Ron DeBruin's site at:
http://www.rondebruin.nl/zip.htm.
I've simply copied & pasted the code relating to "Zip The ActiveWorkbook"
as
a starting point.

Specifically, I'm getting a "Sub Or Function Not Defined" error on the
line
ShellAndWait ShellStr, vbHide

I'm wondering whether a specific required reference is not active, or
whether this function isn't available in this Excel version (2k).
Replacing
ShellAndWait with Shell works ok, but I don't want VBA to continue running
until the zip operation is complete. Yes, I know I could simply insert an
Application.Wait, but this is gonna niggle at me until I know what's going
on!

Any ideas appreciated, cheers!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ShellAndWait Query

Dear all,

I am new to VBA and have also encountered a problem with the ShellandWait
function on Ron DeBruin's site. It works perfectly, with the exception that I
get a pop up saying that a file exists every now and again. To save me having
to sit at my computer for hours, is there a way to automatically select yes?


This is the code I used:
Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim hProg As Long
Dim hProcess As Long, ExitCode As Long

'fill in the missing parameter and execute the program
If IsMissing(WindowState) Then WindowState = 1
hProg = Shell(PathName, WindowState)
'hProg is a "process ID under Win32. To get the process handle:
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
Do
'populate Exitcode variable
GetExitCodeProcess hProcess, ExitCode
DoEvents
Loop While ExitCode = STILL_ACTIVE
End Sub


I have tried inserting application.displayalerts = false/true and this does
not work.

I would greatly appreciate any help!

Thank you!

"DS" wrote:

Afternoon all,

I'm hitting a slight problem trying to get the ShellAndWait command running,
using the example on Ron DeBruin's site at: http://www.rondebruin.nl/zip.htm.
I've simply copied & pasted the code relating to "Zip The ActiveWorkbook" as
a starting point.

Specifically, I'm getting a "Sub Or Function Not Defined" error on the line
ShellAndWait ShellStr, vbHide

I'm wondering whether a specific required reference is not active, or
whether this function isn't available in this Excel version (2k). Replacing
ShellAndWait with Shell works ok, but I don't want VBA to continue running
until the zip operation is complete. Yes, I know I could simply insert an
Application.Wait, but this is gonna niggle at me until I know what's going on!

Any ideas appreciated, cheers!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default ShellAndWait Query

I didn't look at Ron's site and I don't see anything in the code you posted that
would cause that warning...

But maybe you could delete the file that's causing the error before you use the
ShellAndWait procedu

On Error Resume Next
Kill "C:\somepath\somefilenamehere.extensionhere"
on error goto 0



abcdefg wrote:

Dear all,

I am new to VBA and have also encountered a problem with the ShellandWait
function on Ron DeBruin's site. It works perfectly, with the exception that I
get a pop up saying that a file exists every now and again. To save me having
to sit at my computer for hours, is there a way to automatically select yes?

This is the code I used:
Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
Dim hProg As Long
Dim hProcess As Long, ExitCode As Long

'fill in the missing parameter and execute the program
If IsMissing(WindowState) Then WindowState = 1
hProg = Shell(PathName, WindowState)
'hProg is a "process ID under Win32. To get the process handle:
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
Do
'populate Exitcode variable
GetExitCodeProcess hProcess, ExitCode
DoEvents
Loop While ExitCode = STILL_ACTIVE
End Sub

I have tried inserting application.displayalerts = false/true and this does
not work.

I would greatly appreciate any help!

Thank you!

"DS" wrote:

Afternoon all,

I'm hitting a slight problem trying to get the ShellAndWait command running,
using the example on Ron DeBruin's site at: http://www.rondebruin.nl/zip.htm.
I've simply copied & pasted the code relating to "Zip The ActiveWorkbook" as
a starting point.

Specifically, I'm getting a "Sub Or Function Not Defined" error on the line
ShellAndWait ShellStr, vbHide

I'm wondering whether a specific required reference is not active, or
whether this function isn't available in this Excel version (2k). Replacing
ShellAndWait with Shell works ok, but I don't want VBA to continue running
until the zip operation is complete. Yes, I know I could simply insert an
Application.Wait, but this is gonna niggle at me until I know what's going on!

Any ideas appreciated, cheers!


--

Dave Peterson
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
Use MS Query to query data within the current work book Steve Kesler Excel Discussion (Misc queries) 0 August 6th 09 05:22 PM
Convert hard coded query criteria to Parameter Query Melanie[_2_] Excel Discussion (Misc queries) 0 July 15th 08 09:59 PM
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
Save data retreived from query without saving query Anthony Excel Discussion (Misc queries) 0 January 25th 06 07:17 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 04:10 AM.

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

About Us

"It's about Microsoft Excel"