Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code needed to print multiple workbooks


I have a large collection of workbooks, and need to be able to print a
specified number of each from a master workbook which looks like this:

Title No. Reqd
A 3
D 2
F 0
X 2

Originally, this was meant to be only one workbook, with a worksheet
for each title, so I had the following code -

Sub Dostuff()

Dim a As String
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer

'Clear variable
a = ""

'get number of worksheets
d = Worksheets.Count

'go down the list getting the name of the worksheet and
'the amount needed

For b = 2 To d

a = Worksheets("Master").Cells(b, 1).Value
c = Worksheets("Master").Cells(b, 2).Value

'print needed amount of worksheet

Worksheets(a).PrintOut Copies:=c

'loop till end

Next b

End Sub


This worked perfectly, but now the worksheet contents have been made
into individual workbooks (all stored in the same folder, and with
names corresponding to the 'Title' column on the master document). What
changes do I need to make to the above code to work with seperate
workbooks? Or do I need to start again from scratch?


--
madbloke
------------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...o&userid=14422
View this thread: http://www.excelforum.com/showthread...hreadid=392477

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Code needed to print multiple workbooks

Assumes: Title is the file name, without the .xls, and all files (including the one with the Master
sheet) reside in the same folder.

Sub Dostuff2()

Dim a As String
Dim b As Integer
Dim c As Integer

'go down the list getting the name of the worksheet and
'the amount needed

For b = 2 To Worksheets("Master").Cells(65536, 1).End(xlUp).Row

a = Worksheets("Master").Cells(b, 1).Value
c = Worksheets("Master").Cells(b, 2).Value

'print needed amount of worksheet

Workbooks.Open a & ".xls"
ActiveSheet.PrintOut Copies:=c
ActiveWorkbook.Close False

'loop till end

Next b

End Sub

HTH,
Bernie
MS Excel MVP


"madbloke" wrote in message
...

I have a large collection of workbooks, and need to be able to print a
specified number of each from a master workbook which looks like this:

Title No. Reqd
A 3
D 2
F 0
X 2

Originally, this was meant to be only one workbook, with a worksheet
for each title, so I had the following code -

Sub Dostuff()

Dim a As String
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer

'Clear variable
a = ""

'get number of worksheets
d = Worksheets.Count

'go down the list getting the name of the worksheet and
'the amount needed

For b = 2 To d

a = Worksheets("Master").Cells(b, 1).Value
c = Worksheets("Master").Cells(b, 2).Value

'print needed amount of worksheet

Worksheets(a).PrintOut Copies:=c

'loop till end

Next b

End Sub


This worked perfectly, but now the worksheet contents have been made
into individual workbooks (all stored in the same folder, and with
names corresponding to the 'Title' column on the master document). What
changes do I need to make to the above code to work with seperate
workbooks? Or do I need to start again from scratch?


--
madbloke
------------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...o&userid=14422
View this thread: http://www.excelforum.com/showthread...hreadid=392477



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code needed to print multiple workbooks


That did the trick.

I had to add the folder path to it, though. Is there any way of makin
it relative (i.e. it works wherever the files and master sheet ar
saved)

--
madblok
-----------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...fo&userid=1442
View this thread: http://www.excelforum.com/showthread.php?threadid=39247

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Code needed to print multiple workbooks

Workbooks.Open ThisWorkbook.Path & "\" & a & ".xls"

HTH,
Bernie
MS Excel MVP


"madbloke" wrote in message
...

That did the trick.

I had to add the folder path to it, though. Is there any way of making
it relative (i.e. it works wherever the files and master sheet are
saved)?


--
madbloke
------------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...o&userid=14422
View this thread: http://www.excelforum.com/showthread...hreadid=392477



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
Print selected worksheets in multiple workbooks? T & I Forms Excel Discussion (Misc queries) 1 April 3rd 10 11:52 PM
Help needed on a function for multiple workbooks from 1 main workb Sarcalogus Excel Worksheet Functions 0 October 8th 09 10:38 AM
Print routine needed for code pano Excel Worksheet Functions 3 February 11th 07 02:27 PM
Print Multiple Workbooks malycom Excel Discussion (Misc queries) 0 March 10th 06 09:51 AM
VBA code in multiple workbooks Jon[_14_] Excel Programming 1 January 7th 04 04:29 PM


All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"