View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Darla
 
Posts: n/a
Default Open many workbooks in Excel & print one page

Thanks for responding so quickly, Ron!

I tried what you suggested and received an "invalid procedure call or
argument" error message. Could it be because the files I am accessing are on
a network drive?

Here is part of the macro. The "ChDrive MyPath" was highlighted in yellow
and it was referencing that as the problem..

SaveDriveDir = CurDir
MyPath = "\\mercy-5\cashlogs\WI Clinics\Evansville"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then

Because these files are all on the Network in the cashlogs folder but
located in different folders within that folder am I still going to be able
to do this?

Thanks again for your help!


"Ron de Bruin" wrote:

Hi Darla

Try this for all files in the folder C:\Data
It will print the first sheet of each file.

Copy the code in a normal module in a workbook that is
not in the folder C:\Data.

Open a new workbook
Alt -F11
InsertModule from the menu bar
paste the sub in there
Alt-Q to go back to Excel


If you do Alt-F8 you get a list of your macro's
Select "TestFile1" and press Run


Sub TestFile1()
Dim basebook As Workbook
Dim mybook As Workbook
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String


SaveDriveDir = CurDir
MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)
mybook.Sheets(1).PrintOut
mybook.Close False
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Darla" wrote in message ...
I have 80 workbooks that I need to open and print the summary tab for each
one and then close. Does anyone know how I could do this all at one time?
Is there some kind of macro that would work for this? I am a novice with
macros but would be willing to try but not sure how to begin.

Thank you for your help.