A
asburypark98
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
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