Excel Macro to Open and Print Other Spreadsheets (1 Viewer)

chaddiesel

Registered User.
Local time
Today, 00:36
Joined
Mar 30, 2005
Messages
24
Hello Everyone,

I have a spreadsheet that containts 2 columns-Part Number and Drawing Location. The sheet looks something like this:

---A------------------------B-------------------------
Part#-----------Drawing Location
Part 1----------c:\drawings\part1.xls
Part 2----------c:\drawings\part2.xls
Part 3----------c:\drawings\part3.xls

Is there a way to make a macro that will look at the cell containing the file path, open that Excel file, print the workbook, close the file, move to the next cell down, open/print/close...etc until it reaches a blank cell?

I'm very new to macros, so any help would be greatly appreciated.

Thank You,

-Chad
 

___

¯¯¯¯¯
Local time
Today, 08:36
Joined
Nov 27, 2003
Messages
595
Will the files always be in the same folder?
 

___

¯¯¯¯¯
Local time
Today, 08:36
Joined
Nov 27, 2003
Messages
595
You could use something like this....

Code:
Option Explicit

Private Sub PrintAllWorkbooks()
Dim wb As Workbook
Dim ws As Worksheet
Dim MyFolder
Dim I As Long

    Application.EnableEvents = False
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False

    MyFolder = GetFolder
    If MyFolder = vbNullString Then
        MsgBox "No folder selected, stopping procedure.", vbCritical
        Exit Sub
    End If
   
    With Application.FileSearch
        .NewSearch
        .LookIn = MyFolder
        .FileType = msoFileTypeExcelWorkbooks
        .Execute

        For I = 1 To .FoundFiles.Count
            Set wb = Workbooks.Open(.FoundFiles(I))
            For Each ws In wb.Worksheets
                 ws.PrintOut
            Next ws
            wb.Close
        Next I
    End With
   
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
End Sub

Private Function GetFolder() As String
    Dim ff As Object
    
    Set ff = CreateObject("Shell.Application"). _
             BrowseForFolder(0, "Please select a folder", 0, "c:\\")
    If Not ff Is Nothing Then
        GetFolder = ff.Items.Item.Path
    Else
        GetFolder = vbNullString
    End If

End Function
 

___

¯¯¯¯¯
Local time
Today, 08:36
Joined
Nov 27, 2003
Messages
595
Example...
 

Attachments

  • PrintWorkbooks.zip
    10.6 KB · Views: 389

chaddiesel

Registered User.
Local time
Today, 00:36
Joined
Mar 30, 2005
Messages
24
The files will always be stored in the same folder, but I only want to print the list of files starting with cell b2 on down and not the whole folder. I inserted my data into your spreadsheet and clicked print, selected the folder, and received this message.

Method 'PrintOut' of object '_Worksheet' failed.

I'm sure I'm not doing this right. Sorry, I am new to this.

-Chad
 

chaddiesel

Registered User.
Local time
Today, 00:36
Joined
Mar 30, 2005
Messages
24
The files will always be stored in the same folder, but I only want to print the list of files starting with cell b2 on down and not the whole folder. I inserted my data into your spreadsheet and clicked print, selected the folder, and received this message.

Method 'PrintOut' of object '_Worksheet' failed.

I'm sure I'm not doing this right. Sorry, I am new to this.

-Chad
 

___

¯¯¯¯¯
Local time
Today, 08:36
Joined
Nov 27, 2003
Messages
595
chaddiesel said:
The files will always be stored in the same folder, but I only want to print the list of files starting with cell b2 on down and not the whole folder. I inserted my data into your spreadsheet and clicked print, selected the folder, and received this message.

Method 'PrintOut' of object '_Worksheet' failed.

I'm sure I'm not doing this right. Sorry, I am new to this.

-Chad

Did you try my example?

I would personally group the reports/workbooks in their respective sub folders under the main folder and have the user select which folder they need to print. For example, if the main folder was "Cars", I'd have "Ford", "BMW", "Volvo" etc. as the subfolders holding all relevent information. You could then change this part of the code...
Code:
BrowseForFolder(0, "Please select a folder", 0, "c:\\")
to...
Code:
BrowseForFolder(0, "Please select a folder", 0, "c:\Cars\")
to open automatically in the "Cars" folder listing only the subfolders available for printing.

Hope this helps.
 

Users who are viewing this thread

Top Bottom