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

Tip: Looking for answers? Try searching our database.

Calling Excel from a Word with VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joes - 06 Aug 2005 15:33 GMT
Hello

I am newcomer to VBA. I have to open from Word an Excel file and to
call a custom function from it. It would be great if someone could show
me here some example code or provide me some useful links.

Many thanks
Mark Egloff
Doug Robbins - 06 Aug 2005 15:51 GMT
See the article "Control Excel from Word" at:

http://word.mvps.org/FAQs/InterDev/ControlXLFromWord.htm

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hello
>
[quoted text clipped - 4 lines]
> Many thanks
> Mark Egloff
joes - 06 Aug 2005 16:29 GMT
Many thanks looks good. I have one futher question. How can I call
acustom function from this opened Excel?

thanks
Mark

Dim oWB As Excel.Workbook

'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn)
Doug Robbins - 06 Aug 2005 16:51 GMT
Not quite sure what you mean by a custom function, but via that method, you
will have access to the Excel object model.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Many thanks looks good. I have one futher question. How can I call
> acustom function from this opened Excel?
[quoted text clipped - 6 lines]
> 'Open the workbook
> Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn)
joes - 06 Aug 2005 17:28 GMT
Sorry for my confusion. I have a vb function in my Excel called
"myFunc". How can I call that from Word? simple like this example ?

'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=W­orkbookToWorkOn)
oWB.myFunc("foo")

thanks

regards
Mark
Dawn Crosier - 10 Aug 2005 17:32 GMT
Mark -

oXL.Application.Run ("MacroName")

Should work for you.  If you need to pass arguments to the
Function, intellisense should be able to help prompt you for your
arguments.

From Help:
Example
This example shows how to call the function macro My_Func_Sum,
which is defined on the macro sheet Mycustom.xlm (the macro sheet
must be open). The function takes two numeric arguments (1 and 5,
in this example).
mySum = Application.Run("MYCUSTOM.XLM!My_Func_Sum", 1, 5)
MsgBox "Macro result: " & mySum

Signature

Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.

Sorry for my confusion. I have a vb function in my Excel called
"myFunc". How can I call that from Word? simple like this example
?

'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=W­orkbookToWorkOn)
oWB.myFunc("foo")

thanks

regards
Mark
 
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.