Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
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
Printing Workbooks Té Excel Discussion (Misc queries) 3 August 14th 09 12:33 AM
printing charts from several workbooks tony Charts and Charting in Excel 0 October 11th 06 04:12 AM
publishing worskeets with accents in hyperlinks itarnak[_14_] Excel Programming 0 October 27th 05 03:06 PM
printing multiple workbooks. masagua4u Excel Worksheet Functions 1 April 11th 05 02:05 AM
Printing Mutiple workbooks.... Brady Snow Excel Programming 0 October 28th 03 08:16 PM


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

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"