Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calling an Excel/VBA User Created Module from WSH

Hello

Suppose I have an Excel workbook named Book1.xls. Within this workbook,
there is a Module1 and within it, is the following function:

function getValue(sym as String)
begin
//processing code..


getValue = 10
end

How can I call this function from a Windows Scripting Host (WSH) script?

I have tried the following but I receive an error with the message
"Subscript out of range"

Dim ObjXL
Dim tmp
Dim Range

Set ObjXL = WSCript.CreateObject("Excel.Application")


ObjXL.Visible = true

objXL.WorkBooks.Open("C:\Book1")

Set tmp = ObjXL.Modules("Module1").getValue("hello")

//I have also used Modules(0) and Modules(1)


WScript.Echo tmp

Any help or hints is greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Calling an Excel/VBA User Created Module from WSH

Try,

Dim Result
Result = objXL.Run("test")


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"None" wrote in message
...
Hello

Suppose I have an Excel workbook named Book1.xls. Within this
workbook, there is a Module1 and within it, is the following
function:

function getValue(sym as String)
begin
//processing code..


getValue = 10
end

How can I call this function from a Windows Scripting Host
(WSH) script?

I have tried the following but I receive an error with the
message "Subscript out of range"

Dim ObjXL
Dim tmp
Dim Range

Set ObjXL = WSCript.CreateObject("Excel.Application")


ObjXL.Visible = true

objXL.WorkBooks.Open("C:\Book1")

Set tmp = ObjXL.Modules("Module1").getValue("hello")

//I have also used Modules(0) and Modules(1)


WScript.Echo tmp

Any help or hints is greatly appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calling an Excel/VBA User Created Module from WSH

"Chip Pearson" wrote in news:eE1stOGQFHA.1096
@tk2msftngp13.phx.gbl:

Try,

Dim Result
Result = objXL.Run("test")


Hi Chip

Thanks for the reply. Unfortunately this won't work because a parameter must
be passed to this function. After many hours of trial and error, I moved the
function under the 'Sheet1' object and called the function in this manner:

tmp = ObjXL.WorkSheets("Sheet1").getValue("Hello")

It worked. :)

Take care
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Calling an Excel/VBA User Created Module from WSH



It looks like your function's code is located in the sheet's object
code module. Do you know the difference between object code modules and
normal modules?

if you dont..

stick to following as a general guideline:

move all subs and functions to normal code module(s)
with the exception of eventhandlers, which must stay
in the object modules (This Workbook, Sheet1,Sheet2 etc..)

buy and study a decent book. VBA is a lot more fun in you know the
basics.

hmm... that sounds harsh.. but it's true :)


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


None wrote :

"Chip Pearson" wrote in news:eE1stOGQFHA.1096
@tk2msftngp13.phx.gbl:

Try,

Dim Result
Result = objXL.Run("test")


Hi Chip

Thanks for the reply. Unfortunately this won't work because a
parameter must be passed to this function. After many hours of trial
and error, I moved the function under the 'Sheet1' object and called
the function in this manner:

tmp = ObjXL.WorkSheets("Sheet1").getValue("Hello")

It worked. :)

Take care

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
calling a module [email protected] Excel Discussion (Misc queries) 1 September 28th 07 04:03 PM
Calling for pages before they are created. bsspewer Excel Discussion (Misc queries) 4 March 27th 06 10:55 PM
Calling Worksheet SubProcs From Module Chris Villanueva Excel Programming 3 May 29th 04 02:53 AM
Calling VBA function that is in another module Jag Man Excel Programming 2 January 7th 04 03:37 AM
Calling Macros oustide current module Mic[_2_] Excel Programming 2 October 28th 03 05:52 PM


All times are GMT +1. The time now is 03:12 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"