Openning an excel file

F

Frederico Ottoni

Hello there,

I work with outlook VBA and I have to open an excel file throught code,
but the Excel is not openned. How can I do to open this file?

Thanks,
Ottoni.

*** Sent via Developersdex http://www.developersdex.com ***
 
M

Michael Bauer

Hi,

I´d add a reference to Excel via Tools/References, that makes
IntelliSense available and allows you to explore Excel´s methods etc. in
the Object Browser (F2).

For opening a Workbook please use Workbooks.Open. A sample is availabe
in Excel´s VBA help.
 
F

Frederico Ottoni

Thanks for the response.
But I am already using that and it only works if, before running the
macro, I open the excel. Doing that it works perfectly, open the file I
want, edit every thing I need, close the file... But I do not want the
user have to open the excel before run the system. So, thats my problem.
I am using

Set appExcel = GetObject(, "Excel.Application")
appExcel.Workbooks.Open (strSheet)

Any idea?

Thanks,
Ottoni.


*** Sent via Developersdex http://www.developersdex.com ***
 
M

Michael Bauer

Frederico, you can use your first statement. If it raises an error, i.e.
appExcel is nothing, then you know that Excel isn´t running already. In
that case call CreateObject("Excel.Application") instead of GetObject.
 
Top