#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default macro timer

Hi,
my problem refers to the code below.
It applies on two files (A.xls, B.xls).
My goal is as follow: i want to open the first file
(it updates by DDE) and, after 40 sec., save it and
open the second file and repeat the operations: update
and then, after 40 sec., save it.

But my code opens the two files at the same time.
It saves the last one and then macro stops because
of the error.
I've got a msg: "Run-time error '91'"

I'm looking at the error but I don't see where it
can be... maybe I've used the some wrong
functions.
Could you suggest me something that can help
me ?

Thank you very much,
ap

'-------------------------------------------------
Option Explicit
Public WB As Workbook
Dim arrFiles()
Dim i
'--------------------------------------------------

Public Sub link()

Dim sFile As String
Dim sPath As String

arrFiles = Array("A", "B")
sPath = "C:\FILES\"

For i = 0 To 1
sFile = Dir(sPath & arrFiles(i) & "*.xls")
Workbooks.Open (sPath & arrFiles(i))
open
Next i


End Sub


'---------------------------------------------------

Public Sub open()


Set WB = ActiveWorkbook
Worksheets("Sheet1").Range("AO1:AS38").Calculate

Application.Run (arrFiles(i) & "!" & "DoOnData")
Application.onTime Now + TimeValue("00:00:40"), "saving"

End Sub


'-------------------------------------------------------

Public Sub saving()

WB.Close savechanges:=True
Set WB = Nothing


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default macro timer

One issue I think you have is here. WB is declared as a procedure level
variable, not a module level variable, therefore the "saving" subroutine has
no idea what WB is. See VBA help for variable "scope".

Public Sub saving()

WB.Close savechanges:=True
Set WB = Nothing


End Sub


Also, I wouldn't use "open" for a subroutine name as VBA has it's own open
method with the same name.

My experience is that OnTime won't stop the macro from continuing to process
the next line of code. If you want to wait 40 seconds before proceeding,
perhaps check VBA help for the wait method - it sounds like that may be more
along the lines of what you want to do (I've never actually used or seen this
method before, but this is the second time I've suggested it tonight and I've
only looked at two posts).



"asburypark98" wrote:

Hi,
my problem refers to the code below.
It applies on two files (A.xls, B.xls).
My goal is as follow: i want to open the first file
(it updates by DDE) and, after 40 sec., save it and
open the second file and repeat the operations: update
and then, after 40 sec., save it.

But my code opens the two files at the same time.
It saves the last one and then macro stops because
of the error.
I've got a msg: "Run-time error '91'"

I'm looking at the error but I don't see where it
can be... maybe I've used the some wrong
functions.
Could you suggest me something that can help
me ?

Thank you very much,
ap

'-------------------------------------------------
Option Explicit
Public WB As Workbook
Dim arrFiles()
Dim i
'--------------------------------------------------

Public Sub link()

Dim sFile As String
Dim sPath As String

arrFiles = Array("A", "B")
sPath = "C:\FILES\"

For i = 0 To 1
sFile = Dir(sPath & arrFiles(i) & "*.xls")
Workbooks.Open (sPath & arrFiles(i))
open
Next i


End Sub


'---------------------------------------------------

Public Sub open()


Set WB = ActiveWorkbook
Worksheets("Sheet1").Range("AO1:AS38").Calculate

Application.Run (arrFiles(i) & "!" & "DoOnData")
Application.onTime Now + TimeValue("00:00:40"), "saving"

End Sub


'-------------------------------------------------------

Public Sub saving()

WB.Close savechanges:=True
Set WB = Nothing


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default macro timer

A link to the other post w/what appears to be a similar question.

http://www.microsoft.com/office/comm...2-88d78112fde9


"JMB" wrote:

One issue I think you have is here. WB is declared as a procedure level
variable, not a module level variable, therefore the "saving" subroutine has
no idea what WB is. See VBA help for variable "scope".

Public Sub saving()

WB.Close savechanges:=True
Set WB = Nothing


End Sub


Also, I wouldn't use "open" for a subroutine name as VBA has it's own open
method with the same name.

My experience is that OnTime won't stop the macro from continuing to process
the next line of code. If you want to wait 40 seconds before proceeding,
perhaps check VBA help for the wait method - it sounds like that may be more
along the lines of what you want to do (I've never actually used or seen this
method before, but this is the second time I've suggested it tonight and I've
only looked at two posts).



"asburypark98" wrote:

Hi,
my problem refers to the code below.
It applies on two files (A.xls, B.xls).
My goal is as follow: i want to open the first file
(it updates by DDE) and, after 40 sec., save it and
open the second file and repeat the operations: update
and then, after 40 sec., save it.

But my code opens the two files at the same time.
It saves the last one and then macro stops because
of the error.
I've got a msg: "Run-time error '91'"

I'm looking at the error but I don't see where it
can be... maybe I've used the some wrong
functions.
Could you suggest me something that can help
me ?

Thank you very much,
ap

'-------------------------------------------------
Option Explicit
Public WB As Workbook
Dim arrFiles()
Dim i
'--------------------------------------------------

Public Sub link()

Dim sFile As String
Dim sPath As String

arrFiles = Array("A", "B")
sPath = "C:\FILES\"

For i = 0 To 1
sFile = Dir(sPath & arrFiles(i) & "*.xls")
Workbooks.Open (sPath & arrFiles(i))
open
Next i


End Sub


'---------------------------------------------------

Public Sub open()


Set WB = ActiveWorkbook
Worksheets("Sheet1").Range("AO1:AS38").Calculate

Application.Run (arrFiles(i) & "!" & "DoOnData")
Application.onTime Now + TimeValue("00:00:40"), "saving"

End Sub


'-------------------------------------------------------

Public Sub saving()

WB.Close savechanges:=True
Set WB = Nothing


End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default macro timer

Great thanks JMB !!!!

I've just looked at the web site you suggested me and I used
"Application.Wait" instead of
"Application.Run" command and code seems to be right now !

ap

  #5   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default macro timer

You're welcome.

"asburypark98" wrote:

Great thanks JMB !!!!

I've just looked at the web site you suggested me and I used
"Application.Wait" instead of
"Application.Run" command and code seems to be right now !

ap


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
timer Macro Puzzled Excel Worksheet Functions 3 March 11th 06 09:21 PM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 PM
timer macro Darren Excel Discussion (Misc queries) 1 January 24th 06 01:59 PM
Macro With Timer Event Saxman Excel Discussion (Misc queries) 4 December 12th 05 05:35 PM
timer within a macro Orlando Magalhães Filho Excel Programming 3 September 6th 03 06:54 PM


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

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

About Us

"It's about Microsoft Excel"