Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Macro opens files as it tries to access them !!!

Hi,

I have created a macro in an Excel file which uses the data from several
other Excel files and sheets. It gets the information from these other files
and puts them in the new file. The problem is that, the other files need to
be open at the time when the macro is running and trying to access them! If
they are closed, it gives an error as RUN TIME ERROR 9: SUBSCRIPT OUT OF
RANGE.
I want the macro to run smoothly, accessing the data in the other files
without giving any errors and without even opening them. Because opening them
will slow down the system and I will see a lot of window switching in front
of my eyes!!
Is there a command which I can add at the beginning of the macro to disable
the opening of the files, at the same time enabling access to their data? Or
is there another way of solving this problem.
Please help, as it is very urgent.

Thanks in advance.
Berj

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default Macro opens files as it tries to access them !!!

Maybe you could use a function that doesn't require the other workbook to be
open, like SUMPRODUCT. See
http://www.xldynamic.com/source/xld....tml#advantages
James

"Berj" wrote in message
...
Hi,

I have created a macro in an Excel file which uses the data from several
other Excel files and sheets. It gets the information from these other
files
and puts them in the new file. The problem is that, the other files need
to
be open at the time when the macro is running and trying to access them!
If
they are closed, it gives an error as "RUN TIME ERROR '9': SUBSCRIPT OUT
OF
RANGE".
I want the macro to run smoothly, accessing the data in the other files
without giving any errors and without even opening them. Because opening
them
will slow down the system and I will see a lot of window switching in
front
of my eyes!!
Is there a command which I can add at the beginning of the macro to
disable
the opening of the files, at the same time enabling access to their data?
Or
is there another way of solving this problem.
Please help, as it is very urgent.

Thanks in advance.
Berj



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 256
Default Macro opens files as it tries to access them !!!

Open them. Here is an example of a sub that opens three workbooks by
a specified name. You could add code in-between to copy data from
them to current workbook, or whatever you need done (since you didn't
specify).

Public Sub openWorkbooks()
Dim fileNames(1 To 3) As String
Dim wkb As Excel.Workbook
Dim i As Long

Application.ScreenUpdating = False

fileNames(1) = "Book1.xls"
fileNames(2) = "Book2.xls"
fileNames(3) = "Book3.xls"

For i = LBound(fileNames) To UBound(fileNames)
On Error Resume Next
Set wkb = Application.Workbooks.Open _
(ThisWorkbook.Path & "\" & fileNames(i))
On Error GoTo 0
If wkb Is Nothing Then
Call MsgBox("Workbook " & fileNames(i) & " not found!")
Else
' copy data from current book
wkb.Close
Set wkb = Nothing
End If
Next i

Application.ScreenUpdating = True
End Sub


On Nov 28, 12:56 am, Berj wrote:
Hi,

I have created a macro in an Excel file which uses the data from several
other Excel files and sheets. It gets the information from these other files
and puts them in the new file. The problem is that, the other files need to
be open at the time when the macro is running and trying to access them! If
they are closed, it gives an error as "RUN TIME ERROR '9': SUBSCRIPT OUT OF
RANGE".
I want the macro to run smoothly, accessing the data in the other files
without giving any errors and without even opening them. Because opening them
will slow down the system and I will see a lot of window switching in front
of my eyes!!
Is there a command which I can add at the beginning of the macro to disable
the opening of the files, at the same time enabling access to their data? Or
is there another way of solving this problem.
Please help, as it is very urgent.

Thanks in advance.
Berj


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
Macro to access multiple Excel files [email protected] Excel Discussion (Misc queries) 4 March 7th 07 04:50 PM
Opens 2 files the same Ollie Excel Discussion (Misc queries) 1 March 9th 06 02:08 AM
Excel Opens two files lara5555 Excel Discussion (Misc queries) 1 February 20th 06 03:05 PM
Access.Application.Quit - opens Access again then won't close - He Hluhluwe Excel Programming 0 January 30th 06 11:17 AM
Macro to Access External Files Grumpy Excel Programming 2 March 1st 05 04:17 PM


All times are GMT +1. The time now is 03:44 PM.

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

About Us

"It's about Microsoft Excel"