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 / October 2005

Tip: Looking for answers? Try searching our database.

It works...it works not

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Naz - 31 Oct 2005 01:16 GMT
Hi

I have a macro that copies some cells from Excel and pastes them into Word.

However, the code stops at this line

Set oXL = GetObject(, "Excel.Application")

and gives the message "ActiveX component can't create object"

But the macro works fine if i copy the module to the Normal document template.

Do i have to declare the application call differentetly if calling from
within a document.

All help is appreciated
Signature


_______________________
Naz,
London

Jezebel - 31 Oct 2005 09:59 GMT
GetObject() will fail if you there's no existing instance of Excel to get.
In that case you need to use CreateObject() instead. Fortunately the error
is trappable, you so can use something like ---

ON error resume next
Set oXL = GetObject(, "Excel.Application")
on error goto 0

If oXL is nothing then
   Set oXL = CreateObject("Excel.Application")
end if

> Hi
>
[quoted text clipped - 14 lines]
>
> All help is appreciated
Tony Jollans - 31 Oct 2005 14:32 GMT
I have no idea how you make it work in Normal and not anywhere else. It
should work if you have a currently running instance of Excel, and fail if
not.

AFAIK, the only way to deal with it is to trap the error

On Error Resume next
Set oXL = GetObject(, "Excel.Application")
If Err.Number = 429 then Set oXL = CreateObject("Excel.Application")
On Error Goto 0

--
Enjoy,
Tony

> GetObject() will fail if you there's no existing instance of Excel to get.
> In that case you need to use CreateObject() instead. Fortunately the error
[quoted text clipped - 31 lines]
> > Naz,
> > London

Rate this thread:






 
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.