Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Open file and print sheets based on data in cell

Hi everyone. In column A I have the full path of a file. In columns B
through AZ I have sheet names within that file. How can I code excel to
open the file in A1, print the sheets in B1 through AZ1, then close the
file, then move to the next row and do the same until all rows containing
data in column A have been looped though? Thank you in advance.

PS - Some files may only have 2 sheets to be printed, so D1 through AZ1 may
be blank.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open file and print sheets based on data in cell

Dim rng as Range, rng1 as Range
Dim cell as Range, cell1 as Range
Dim bk as Workbook
set rng = Range("A1").CurrentRegion.columns(1)
for each cell in rng
if trim(cell.value) < "" then
set bk = Workbooks.Open(cell.Value)
set rng1 = Cell.offset(0,1).Resize(1,51).SpecialCells(xlConst ants)
for each cell1 in rng1
if trim(cell1.Value) < "" then
bk.worksheets(cell1.Value).Printout
end if
Next
End if
Next

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Hi everyone. In column A I have the full path of a file. In columns B
through AZ I have sheet names within that file. How can I code excel to
open the file in A1, print the sheets in B1 through AZ1, then close the
file, then move to the next row and do the same until all rows containing
data in column A have been looped though? Thank you in advance.

PS - Some files may only have 2 sheets to be printed, so D1 through AZ1

may
be blank.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Open file and print sheets based on data in cell

Thanks Tom!

"Tom Ogilvy" wrote in message
...
Dim rng as Range, rng1 as Range
Dim cell as Range, cell1 as Range
Dim bk as Workbook
set rng = Range("A1").CurrentRegion.columns(1).Cells
for each cell in rng
if trim(cell.value) < "" then
set bk = Workbooks.Open(cell.Value)
set rng1 = Cell.offset(0,1).Resize(1,51).SpecialCells(xlConst ants)
for each cell1 in rng1
if lcase(cell1.Value) = "all" then
bk.printout
exit for
else
if trim(cell1.Value) < "" then
bk.worksheets(cell1.Value).Printout
end if
end if
Next
End if
Next

Hopefully there are no sheets named All.

--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
Hi Tom. Thanks for the response. Can I ask for one enhancement? I

have
a
few files that have 30 or so pages in them, ALL of which need to be

printed.
Is it possible to edit the code to also allow for the entry "All" in

column
B rather than naming each specific sheet, where that woul trigger excel

to
print all pages within that workbook?

Thanks so much for your help!!

"Tom Ogilvy" wrote in message
...
Dim rng as Range, rng1 as Range
Dim cell as Range, cell1 as Range
Dim bk as Workbook
set rng = Range("A1").CurrentRegion.columns(1)
for each cell in rng
if trim(cell.value) < "" then
set bk = Workbooks.Open(cell.Value)
set rng1 =

Cell.offset(0,1).Resize(1,51).SpecialCells(xlConst ants)
for each cell1 in rng1
if trim(cell1.Value) < "" then
bk.worksheets(cell1.Value).Printout
end if
Next
End if
Next

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Hi everyone. In column A I have the full path of a file. In

columns
B
through AZ I have sheet names within that file. How can I code

excel
to
open the file in A1, print the sheets in B1 through AZ1, then close

the
file, then move to the next row and do the same until all rows

containing
data in column A have been looped though? Thank you in advance.

PS - Some files may only have 2 sheets to be printed, so D1 through

AZ1
may
be blank.











  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open file and print sheets based on data in cell

forgot to close the workbooks:

Dim rng as Range, rng1 as Range
Dim cell as Range, cell1 as Range
Dim bk as Workbook
set rng = Range("A1").CurrentRegion.columns(1).Cells
for each cell in rng
if trim(cell.value) < "" then
set bk = Workbooks.Open(cell.Value)
set rng1 = Cell.offset(0,1).Resize(1,51).SpecialCells(xlConst ants)
for each cell1 in rng1
if lcase(cell1.Value) = "all" then
bk.printout
exit for
else
if trim(cell1.Value) < "" then
bk.worksheets(cell1.Value).Printout
end if
end if
Next
bk.close SaveChanges:=False
End if
Next

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Thanks Tom!

"Tom Ogilvy" wrote in message
...
Dim rng as Range, rng1 as Range
Dim cell as Range, cell1 as Range
Dim bk as Workbook
set rng = Range("A1").CurrentRegion.columns(1).Cells
for each cell in rng
if trim(cell.value) < "" then
set bk = Workbooks.Open(cell.Value)
set rng1 = Cell.offset(0,1).Resize(1,51).SpecialCells(xlConst ants)
for each cell1 in rng1
if lcase(cell1.Value) = "all" then
bk.printout
exit for
else
if trim(cell1.Value) < "" then
bk.worksheets(cell1.Value).Printout
end if
end if
Next
End if
Next

Hopefully there are no sheets named All.

--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
Hi Tom. Thanks for the response. Can I ask for one enhancement? I

have
a
few files that have 30 or so pages in them, ALL of which need to be

printed.
Is it possible to edit the code to also allow for the entry "All" in

column
B rather than naming each specific sheet, where that woul trigger

excel
to
print all pages within that workbook?

Thanks so much for your help!!

"Tom Ogilvy" wrote in message
...
Dim rng as Range, rng1 as Range
Dim cell as Range, cell1 as Range
Dim bk as Workbook
set rng = Range("A1").CurrentRegion.columns(1)
for each cell in rng
if trim(cell.value) < "" then
set bk = Workbooks.Open(cell.Value)
set rng1 =

Cell.offset(0,1).Resize(1,51).SpecialCells(xlConst ants)
for each cell1 in rng1
if trim(cell1.Value) < "" then
bk.worksheets(cell1.Value).Printout
end if
Next
End if
Next

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Hi everyone. In column A I have the full path of a file. In

columns
B
through AZ I have sheet names within that file. How can I code

excel
to
open the file in A1, print the sheets in B1 through AZ1, then

close
the
file, then move to the next row and do the same until all rows
containing
data in column A have been looped though? Thank you in advance.

PS - Some files may only have 2 sheets to be printed, so D1

through
AZ1
may
be blank.













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
Every file I open has print area set to one page per cell steve Excel Discussion (Misc queries) 0 December 11th 07 06:00 PM
When I open a file in excel, I cannot open any of the sheets Barb Excel Worksheet Functions 0 October 30th 06 11:08 PM
Hide Certain Sheets based on Cell Data Volsfan Excel Programming 2 August 10th 05 02:26 PM
Code to transfere all cell data in one old file to a new open? Maria J-son Excel Programming 0 June 10th 05 02:29 PM
cut & paste between sheets based on cell data Mike Reisinger Excel Programming 5 December 10th 03 10:14 AM


All times are GMT +1. The time now is 11:16 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"