Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    VBA to print multiple workbooks! (Excel 2000 >)

    Hi all,
    Does anyone out there has some sample code that will print the first sheet in multiple workbooks! I have someone that stores lots of workbooks in a folder on the C: drive. They want to click a button that will trigger a macro to open a workbook, print the first sheet and close it, then open the next workbook, print the first worksheet, and close, etc.

    They mentioned that they attempted to select all the workbooks in the open dialog and right click and choose print. But that did not work and produced the incorrect results.
    Regards,
    Rudi

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA to print multiple workbooks! (Excel 2000 >)

    You can use the old BASIC Dir statement to loop through the workbooks in a folder:

    Sub PrintMultiple()
    ' Modify as needed, but keep the trailing backslash
    Const strPath = "C:Excel"
    Dim strFile As String

    strFile = Dir(strPath & "*.xls")
    Do While Not strFile = ""
    With Workbooks.Open(Filename:=strPath & strFile, AddToMRU:=False)
    .Sheets(1).PrintOut
    .Close SaveChanges:=False
    End With
    strFile = Dir
    Loop
    End Sub

  3. #3
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA to print multiple workbooks! (Excel 2000 >)

    Thanx Hans. I will try this code and see it it satisfies the needs of one of my collegues!
    Regards,
    Rudi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •