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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application Automation 1

Status
Not open for further replies.

rdmartin

Programmer
Dec 30, 2002
8
0
0
US
I am looking for a way to programtically open a specific Excel Spreadsheet to print preview mode. Any Ideas?
 
First, create excel instance:
[tt]set xlApp=CerateObject("Excel.Application")[/tt]
open excel workbook:
[tt]set xlWbk=xlApp.Workbooks.Open("c:\MyWorkbook.xls"[/tt]
make it visible:
[tt]xlApp.Visible=True[/tt]
(select a sheet if necessary:
[tt]xlWbk.Sheets(3).Select[/tt])
set preview mode:
[tt] xlWbk.PrintPreview

combo
 
I think the above will be more flexible but this also works

Call Shell("excel", vbMaximizedFocus)
 
Don't forget to set a reference to the Excel library prior to using the code.
From the code window, click Tools/References/ and put a check mark by Microsoft Excel (whatever version number) and click OK.
 
Nicely done all! Just a couple things I noticed in Combo source code:

You will probably need a dim statement first:

Dim xlApp As Object

Misc:

Should be CreateObject
No ) after .Select
xlWbk.Sheets("YourSheetName").Select 'Can use name or number

Clean up when finished:

xlApp.Quit
Set xlApp = Nothing
Set xlWBk = Nothing

Good LucK!
 
hi,
I am having a similiar problem.
I need to get to the worksheets which have there own names like "ER0102". I could not understand the code posted by SBendBuckeye.

Should be CreateObject
No ) after .Select
xlWbk.Sheets("YourSheetName").Select 'Can use name or number

could this be elaborated a bit

Thanks

Qureshi
 
Sorry for the confusion.

1. You need a Dim statement like so before you can use it:

Dim xlApp As Object

2. In Combo's original code this line appeared:

xlWbk.Sheets(3).Select)

There should be no ) after the Select

3. At the end of our code just before you exit add this:

xlApp.Quit
Set xlApp = Nothing
Set xlWBk = Nothing

Hope this helps! Good Luck!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top