VBA- Application.Wait?

  • Thread starter Thread starter Mel
  • Start date Start date
M

Mel

Does PowerPoint not have "Application.Wait" like Excel? Is there
another way to pause code for a few seconds in PPT 2003/2007 while a
small bat file runs?

-Mel
 
Does PowerPoint not have "Application.Wait" like Excel? Is there
another way to pause code for a few seconds in PPT 2003/2007 while a
small bat file runs?

-Mel

From Example 8.4 on my Web site (http://www.PowerfulPowerPoint.com/):

Sub Wait()
waitTime = 5
Start = Timer
While Timer < Start + waitTime
DoEvents
Wend
End Sub

This will wait for 5 seconds.

--David

--
David M. Marcovitz
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
Microsoft PowerPoint MVP
Associate Professor, Loyola University Maryland
 
Does PowerPoint not have "Application.Wait" like Excel? Is there
another way to pause code for a few seconds in PPT 2003/2007 while a
small bat file runs?

-Mel

Does PowerPoint not have "Application.Wait" like Excel? Is there
another way to pause code for a few seconds in PPT 2003/2007 while a
small bat file runs?

-Mel
Alternatively, you could set the BAT file to output a log file.

echo Hello world! >> "C:\new text document.txt" or
echo Hello world! > "C:\new text document.txt"

>> appends text into the "C:\new text document.txt" (you will have multiple "Hello World!" entries in the file)

> simply replaces the text in "C:\new text document.txt" each time.

Use this routine to create a "C:\LogFile.txt". You can then import it into your application using a routine similar to the following:

Sub Input_Text(TextFileLocation As String, MyString As String)
'We will send the file location to this subroutine
'We include the MyString string in the declaration so that it can be returned
Dim FF As Integer

FF = FreeFile()
Open (TextFileLocation) For Binary As FF

'For a string, do this:
MyString = Space(LOF(FF))
Get FF, , MyString

Close FF
End Sub


Call this routine in this fashion:
Input_Text "C:\LogFile.txt", TextString

This will open your target document and return the text within it to the TextString variable

You can embed this read routine in a Do Loop with a failsafe counter number in the millions. Such as:

Sub Main_Sub()
dim i as long
dim choice as integer
dim return as Integer
Dim TextString as String

'this executes the bat file
return = shell("C:\batfile.bat")

Do While Not TextString = "complete"
'Call the input routine
Input_Text "C:\LogFile.txt", TextString
i = i + 1

If i > 1000000 Then
choice = msgbox("File not found. Continue?", vbYesNo)
if choice = 6 then
Exit Sub
end if
else
'reset the i value to resume the loop if not found
i = 0
end if
End Sub
I haven't executed the aforementioned timer routine; still trying to finesse it. Hopefully the above routine will facilitate someone attempting to utilize an external BAT file execution routine.

Furthermore, using the "Print" command you can actually create custom bat files according to the logic you have embedded in your macro.

I created an application that queried the active directory user list from the domain controller, retrieved every security group they were in and then charted them according to organizational unit, adding new users if they did not yet exist on the spreadsheet.

Just FYI, I haven't tested any of the above code so it could be RIFE with syntax errors.
 
Back
Top