View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Opening Excel from Access

To use Excel in Access:
In your VBA "References" include a reference to the Microsoft Excel Object
Model. Then you can use code as illustrated below:

Dim XLApp as Excel.Application, XLBook as Excel.Workbook, XLSheet as
Excel.Worksheet

Set XLApp = New Excel.Application
Set XLApp.Visible = True ' (only if you need the user to see Excel -
otherwise you can process everything invisibly)
Set XLBook = XLApp.Workbooks.Open(WorkbookFilePath)
Set XLSheet = XLBook.Sheets("Sheet1")
etc...
Basically anything possible in Excel VBA is done in your Access module as
long as you refer it back to XLApp. When done be sure to close everything
and clean out your object variables, or you may leave your Excel session
running in the background:
XLBook.Close
XLApp.Quit
Set XLSheet = Nothing
Set XLBook = Nothing
Set XLApp = Nothing

As for the other parts of your question:
- You can open the book read only: the full syntax of the Open method for
the workbook is:
expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password,
WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable,
Notify, Converter, AddToMRU)
So you can use the parameters (in this case, ReadOnly) to specify how to
open the workbook - see help for more info.
- Running macros: I don't know any way to open Excel from code and bypass
the macros prompt - doing so would defeat the purposes of macro security
anyway. I have seen the same question asked before in this forum, so you
could search and see if you can find a solution.

HTH!

"Steve Price" wrote:

Didn't know whether to post this here or under Access.

Basically, how do you open an Excel worksheet from Access in code?

Also, the Excel worksheet uses Macro's and is read only/protected. Is it
possible for the warnings to be surpressed? i.e. Instead of the user being
asked whether to allow macros, these are automatically allowed. And instead
of accessing to enter password to modify workbook, 'read only' is
automatically chosen.


Thanks