Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Printing worskeets in several workbooks
I have about 20 folders with similar names such as ABC00, ABC01, ABC02,
ABC04, and so on. Most of them are consinuous. Each folder consists of an excel file with the same name as the folder: ABC00.xls, ABC01.xls, and so on. I need to print out the first worksheet of each file. Is there a way to do that using macro? Thanks in advance, Lisa |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Printing worskeets in several workbooks
Option Explicit
Sub testme01() Dim iCtr As Long Dim TestStr As String Dim myBaseFolder As String Dim myPfx As String Dim myFileName As String Dim TempWkbk As Workbook myBaseFolder = "C:\my documents\excel" If Right(myBaseFolder, 1) < "\" Then myBaseFolder = myBaseFolder & "\" End If myPfx = "ABC" For iCtr = 1 To 20 'twenty folders??? 'c:\my documents\excel\abc##\abc##.xls myFileName = myBaseFolder _ & myPfx & Format(iCtr, "00") & "\" _ & myPfx & Format(iCtr, "00") & ".xls" Set TempWkbk = Nothing On Error Resume Next Set TempWkbk = Workbooks.Open(Filename:=myFileName, ReadOnly:=True) On Error GoTo 0 If TempWkbk Is Nothing Then 'warning message??? MsgBox myFileName & " wasn't opened!" Else On Error Resume Next TempWkbk.Worksheets(1).PrintOut If Err.Number < 0 Then MsgBox "First sheet not printed in: " & myFileName Err.Clear End If On Error GoTo 0 End If Next iCtr End Sub (Untested, but it did compile.) If you're new to macros, you may want to read David McRitchie's intro at: http://www.mvps.org/dmcritchie/excel/getstarted.htm lwidjaya wrote: I have about 20 folders with similar names such as ABC00, ABC01, ABC02, ABC04, and so on. Most of them are consinuous. Each folder consists of an excel file with the same name as the folder: ABC00.xls, ABC01.xls, and so on. I need to print out the first worksheet of each file. Is there a way to do that using macro? Thanks in advance, Lisa -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Printing Workbooks | Excel Discussion (Misc queries) | |||
printing charts from several workbooks | Charts and Charting in Excel | |||
publishing worskeets with accents in hyperlinks | Excel Programming | |||
printing multiple workbooks. | Excel Worksheet Functions | |||
Printing Mutiple workbooks.... | Excel Programming |