Posted on 2005-04-17
Last Modified: 2010-05-02
This is a second part to a previously solved problem:

I now need to use the corrected syntax in a loop from 000001 to 10673 with the number format having 6 digits.


Question by:csho
    LVL 28

    Expert Comment

    Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    Const STILL_ACTIVE = &H103

    Private Function ShellWait(PathName, Optional WindowStyle As VbAppWinStyle = vbNormalFocus) As Double
    Dim hProcess As Long, RetVal As Long
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(PathName, WindowStyle))
            GetExitCodeProcess hProcess, RetVal
            DoEvents: Sleep 100
        Loop While RetVal = STILL_ACTIVE
    End Function

    Private Sub Command1_Click()
    Dim x As Long
    For x = 1 To 10673
        ShellWait Chr$(34) & "C:\Program Files\IrfanView\i_view32.exe" & Chr$(34) & " /multitif=(c:\sample\mtout\" & Format(x, "#000000") & ".tif,c:\sample\mt\" & Format(x, "#000000") & ".tif,C:\FAQ\FAQ.tif)", vbNormalFocus
    Next x
    End Sub
    LVL 28

    Accepted Solution

    In the above comment I am assuming that you will need to wait for each command to finish before going on to the next one. If not,you can use Shell Instead of ShellWait. Also,If the program launches a window you can replace vbNormalFocus with vbHide to not show it.

    Author Comment

    Again, thank you.
    LVL 28

    Expert Comment

    Your welcome. Thanks for the points.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now