Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Opening Excel from Access

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Opening Excel from Access

I think you must have tried already, but forgot to set Excel to visible.
Once you set it to visible all remaining code is same as in excel macros.
You can use below code.

Sub olExcelOpen()
Dim exApp As Excel.Application
Dim myBook As Excel.Workbook
Set exApp = CreateObject("Excel.Application")
exApp.Visible = True
Set myBook = exApp.Workbooks.Open(FileName:="Path to the file",
ReadOnly:=True)
myBook.RunAutoMacros xlAutoOpen
End Sub

Sharad

"Steve Price" wrote in message
...
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



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
Opening an ACCESS db from the VBE in EXCEL Doctorjones_md Excel Discussion (Misc queries) 4 April 20th 07 07:35 PM
Opening an ACCESS db from the VBE in EXCEL doctorjones_md[_2_] Excel Worksheet Functions 0 April 20th 07 07:35 PM
Opening Access From Excel Kieron White Excel Discussion (Misc queries) 3 April 2nd 06 05:34 PM
Opening Access from Excel Cindy Excel Programming 4 January 14th 04 01:27 PM
Opening Excel via Access Dave[_32_] Excel Programming 1 October 21st 03 06:23 PM


All times are GMT +1. The time now is 01:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"