If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Use Excel via Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-04, 15:11
sreedva sreedva is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
Question Use Excel via Access

This is a multi-part question...

1) From within my Access-2000 application (button-clicked event on a form), I want to open an Excel file that has macros in it AND launch a macro.

2) From within the now opened Excel file, I want to reference the values of Unbound fields on the forms in the Access application.

I created an excel file to test -- initially with no macros.

This event code worked fine to open the file, and make it the visible and active application:

Dim MyXL as Object
Set MyXL = GetObject("C:\QUERYOUTPUT_001.XLS")
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True

Next, I added a simple macro (Macro1 -- it puts the current row number in the active cell). Also note that Macro security is set to Medium. With this setting, if I open the excel file manually, I get a pop-up window that ask me to choose "Enable" or "Disable" macros.

When I run the event code to open the file with macros, I get a different pop-up titled "Microsoft Excel" that has more verbiage (about the file has macros, yadda-yadda...) and offers three choices "Yes", "No", "Cancel"

If I click on "No", the macro does not function (as expected).

If I click on "Yes", the macro still does not function -- and I get a pop-up box titled "Microsoft Excel" that says "The macro 'Macro1' cannot be found."

Any help would be greatly appreciated.

-smr
Reply With Quote
  #2 (permalink)  
Old 06-04-04, 02:04
namliam namliam is offline
Registered User
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 421
You can "Simply" run your code from within access thus avoiding the excel security...

In Access just add myxl. infront of every line you would have in excel, and pronto... It works...

Regards
Reply With Quote
  #3 (permalink)  
Old 06-04-04, 14:17
sreedva sreedva is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
I am hoping to make it all invisible to the end-user. So, if there is a way to automate the process of getting past the pop-up box for security and still be able to run the macros, that'd be great.

Anyone?
Reply With Quote
  #4 (permalink)  
Old 06-04-04, 14:51
accessnoobie accessnoobie is offline
Registered User
 
Join Date: Feb 2004
Posts: 42
Not sure if this would be the "best" way to do it (or even if it would work), but you could consider using the send key function to press enter (or tab to select the right button, then enter) to enable macros when excel starts, then start your macro after that.

Excel does not ask me if I want to enable macros when I open it. I have my Macro saved to my personal macro workbook, as appossed to "new workbook" or "this workbook", so that may be why.

Hope that helps, let me know if need some more info...I'll try.

Noobie
Reply With Quote
  #5 (permalink)  
Old 06-04-04, 15:19
sreedva sreedva is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
I must be misunderstanding something....

This time I tried creating the test file (File1) with no macros. I also created a 2nd file (File2) with the macro (Macro1) I want to ultimately be used.

So I can open File1 using the code shown above fine. But how do I now execute any macros?

-smr
Reply With Quote
  #6 (permalink)  
Old 06-04-04, 18:21
accessnoobie accessnoobie is offline
Registered User
 
Join Date: Feb 2004
Posts: 42
When I make a macro in excel, I always start it by going to Tools / Macro / Record New Macro. When the pop up window to select the keys to run the macro appears, I name the macro, I select what every key combination I want (ie ctrl-shift-p), and then I select store macro in "Personal Macro Workbook". That way the macro can be run for any excel workbook you open or create. Does that make sense?

So what are you doing with this file? Are you going to keep adding more data to the same file, or are you going to make a new file with new data every time?

Once the excel file is open from the access code, I just used the Sendkey function (in Access code) to start the macro. Ie: SendKey "^+p", 5

Hope that helps,
Noobie
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On