Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am encountering a situation where my visual basic for
applications code is running too fast, i.e., it is not waiting until the previous part of the code is completed before moving to the next line. For example, in line 1, I am issuing code to create a folder and in line 2, I am issuing code to access the foler created at line 1 - however, the code is jumping to line 2 before line 1 has completed its job of creating a new folder, with the result that I am receiving a Folder not found error which should not arise had the code waited for line 1 to complete before executing line 2. I tried to include the 'Wait' method of a few seconds delay between line 1 and 2 but it still does not work frequently. Why is this happenning? Is there a way to make the code to go slow, to go one line at a time? Appreciate any comments. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try:
While If Dir(sSDirectory, vbDirectory) = "" Application.Wait Now() + TimeSerial(0, 0, 1) Wend Bob Flanagan Macro Systems http://www.add-ins.com Productivity add-ins and downloadable books on VB macros for Excel "Viswanath Tumu" wrote in message ... I am encountering a situation where my visual basic for applications code is running too fast, i.e., it is not waiting until the previous part of the code is completed before moving to the next line. For example, in line 1, I am issuing code to create a folder and in line 2, I am issuing code to access the foler created at line 1 - however, the code is jumping to line 2 before line 1 has completed its job of creating a new folder, with the result that I am receiving a Folder not found error which should not arise had the code waited for line 1 to complete before executing line 2. I tried to include the 'Wait' method of a few seconds delay between line 1 and 2 but it still does not work frequently. Why is this happenning? Is there a way to make the code to go slow, to go one line at a time? Appreciate any comments. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Many thanks for the suggestion which I am sure will solve
my problem. Regards -----Original Message----- Try: While If Dir(sSDirectory, vbDirectory) = "" Application.Wait Now() + TimeSerial(0, 0, 1) Wend Bob Flanagan Macro Systems http://www.add-ins.com Productivity add-ins and downloadable books on VB macros for Excel "Viswanath Tumu" wrote in message ... I am encountering a situation where my visual basic for applications code is running too fast, i.e., it is not waiting until the previous part of the code is completed before moving to the next line. For example, in line 1, I am issuing code to create a folder and in line 2, I am issuing code to access the foler created at line 1 - however, the code is jumping to line 2 before line 1 has completed its job of creating a new folder, with the result that I am receiving a Folder not found error which should not arise had the code waited for line 1 to complete before executing line 2. I tried to include the 'Wait' method of a few seconds delay between line 1 and 2 but it still does not work frequently. Why is this happenning? Is there a way to make the code to go slow, to go one line at a time? Appreciate any comments. . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Having your code to create a Directory as a function seems to work on my
system. A return code of 0 indicates the Folder was added. You could test this code if you want. When I run "MyCode", it returns the following. The 0 indicates the Folder was added, and the "Temp7" indicates that the folder exists. Not sure what other timing issues might be though. 0 Temp7 Function MakeDir(s As String) On Error Resume Next MkDir s MakeDir = Err.Number End Function Sub MyCode() Dim Result Dim sFolder As String sFolder = "C:\Temp7" Debug.Print MakeDir(sFolder) Debug.Print Dir(sFolder, vbDirectory) End Sub HTH Dana DeLouis "Viswanath Tumu" wrote in message ... I am encountering a situation where my visual basic for applications code is running too fast, i.e., it is not waiting until the previous part of the code is completed before moving to the next line. For example, in line 1, I am issuing code to create a folder and in line 2, I am issuing code to access the foler created at line 1 - however, the code is jumping to line 2 before line 1 has completed its job of creating a new folder, with the result that I am receiving a Folder not found error which should not arise had the code waited for line 1 to complete before executing line 2. I tried to include the 'Wait' method of a few seconds delay between line 1 and 2 but it still does not work frequently. Why is this happenning? Is there a way to make the code to go slow, to go one line at a time? Appreciate any comments. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macros Running Sometimes Slow Sometimes Fast | Excel Discussion (Misc queries) | |||
running code | New Users to Excel | |||
Book on how to write VBA code in a fast/efficient manner? | Excel Programming | |||
running VB code | Excel Programming | |||
Running Code in an XLA from a Worksheet | Excel Programming |