Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

How to close embedded workbook properly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yulia Gillerson - 23 May 2006 08:15 GMT
Hello!

1. I create new MS Word 2003 document.
2. Add reference to Excel.
3. Insert embedded Excel object.
4. Run the following code:

Function OpenAndCloseExcel()
   
   Dim objWorkBook As excel.Workbook
   Dim objExcel As excel.Application
   
   ActiveDocument.InlineShapes(1).OLEFormat.DoVerb
VerbIndex:=wdOLEVerbPrimary
   
   Set objWorkBook = ActiveDocument.InlineShapes(1).OLEFormat.Object
   Set objExcel = objWorkBook.Application
   
   objWorkBook.Close
   objExcel.Quit
   
End Function

Function fails - error 1004, method 'close' of object '_workbook' failed.

5. I run the same function again, Excel objext already activated on step 4.
Function does not fails, Excel removed from task manager.

Could you, please, describe
1. Why function fails on step 4?
2. How to close embedded workbook & excel application properly?

Thank you very much in advance.
macropod - 23 May 2006 10:18 GMT
Hi Yulia,

Provided your activated object will be the one processing keyboard commands,
you can use SendKeys to deactivate the object. For example:
SendKeys "{esc}", Wait:= True

However, if you have a UserForm open while you're activating objects, the
UserForm will trap the keyboard events and this approach won't work.

Cheers

> Hello!
>
[quoted text clipped - 29 lines]
>
> Thank you very much in advance.
Yulia Gillerson - 23 May 2006 10:58 GMT
macropod,

> Provided your activated object will be the one processing keyboard commands,
> you can use SendKeys to deactivate the object. For example:
> SendKeys "{esc}", Wait:= True

Thank you for your answer. I use this method, but Word often hangs until
I'll press Ctrl-Alt-Del and open task manager :(.  

I hope, that exists more stable and simple method.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.