Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delay the macros with Application.Wait Now + TimeValue("00:00:02")

Status
Not open for further replies.

Thosnow

Aerospace
Feb 23, 2017
68
CA
Hello All, I am trying to delay the macro from running for 2 seconds as per VBA code below. But it does not work and give me an error message at statement:
Application.Wait Now + TimeValue("00:00:02").

I also tried to use a MsgBox and SendKeys "{Enter}" trying to delay the program from runing , True, but it does not work either.
So, what is the right syntax or command to delay the macro for 2 more few seconds?

Remember, it is VBA code, not VB or CATScript. Please help me out.

Thank you

===================================
'Program purpose: To delay running the code 2 seconds before switching the cameras

Sub CAMERA()

Dim my3DViewer
Set my3DViewer = CATIA.ActiveWindow.ActiveViewer

MsgBox CATIA.ActiveDocument.Cameras.Count

CATIA.RefreshDisplay = True
MsgBox "Macro is running..."
' SendKeys "{Enter}", True '''' I tried this function, but it did not work well. So, I put it in comment text

Dim oCamera3D As Camera3D
Dim CameraIdent
For CameraIdent = 1 To CATIA.ActiveDocument.Cameras.Count
Set oCamera3D = CATIA.ActiveDocument.Cameras.Item(CameraIdent)
MsgBox oCamera3D.Name '//// Display camera's name

Dim Application
Set Application = CATIA
Application.Wait Now + TimeValue("00:00:02") ' Error here: "method or property is not supported"

CATIA.StartCommand "Fit All In" ' Testing lines of code above

Next
End Sub
==========================================
Thank you in advance

Quin
 
Replies continue below

Recommended for you

Hi,

Why delay "2 seconds?"

Usually a Wait is used in some asynchronous situation, where, for instance, a command is issued to some system over which the program has no control, and the program must wait for that other system to complete some process, and the Wait must continue until the program can detect something that is an indication that that process is done.

That's accomplished in a loop, with DoEvents to enable all processes (not just the loop process) and a test of the something that is an indication that the process is done.

That something, is what you need to find. What can indicate to your program that the paste is complete? It can't be "2 seconds!"
Code:
Do Until ([b]something[/b] exists)
   DoEvents
Loop

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top