Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Printing Entire Workbook 2

Status
Not open for further replies.

cranebill

IS-IT--Management
Joined
Jan 4, 2002
Messages
1,113
Location
US
I am trying to print a specific sheet, and when I go to Print it prints the entire workbook. How do I print only the sheet. Here is my code.

strExcelFile = "c:\Sheets.xls"
Set xlobj = CreateObject("excel.application")
With xlobj
.Visible = True
.Workbooks.Open Filename:=strExcelFile
CatCutSheet = Rs1!CutSheet
Set Sheet = .Worksheets(CatCutSheet)
With Sheet

.Cells(5, 3).Value = Rs1!P
.Cells(7, 1).Value = Rs1!Q
End With

.ActiveWorkbook.PrintOut
.ActiveWorkbook.Close SaveChanges:=False
End With
xlobj.Application.Quit
Set xlobj = Nothing


Bill
 
Hi,

You need to use..

.ActiveSheet.PrintOut

not

.ActiveWorkbook.PrintOut



There are two ways to write error-free programs; only the third one works.
 
Thanx... I tried .Sheet.Printout

Should have thought of that lol

Bill
 
No problems, have spent many an (happy?!) hour messing about with Excel automation trying to find exactly the right commands....



There are two ways to write error-free programs; only the third one works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top