Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBSCRIPT AND EXCEL MACRO

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,58484
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBSCRIPT AND EXCEL MACRO
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 VBSCRIPT AND EXCEL MACRO - 3/27/2008 10:14:36 PM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
Hi all
I am trying to open an excel sheet through vbscript and run a macro written in it.
I have been successfull in opening the excel sheet and running the macro but i do get a runtime script error.
Here is the code that i have written

sub openexcel()
     Dim obj
     Set obj = CreateObject("Excel.application")
     obj.Workbooks.Open "C:/Final templates/MyExcel.xls"
     obj.visible=true
     On Error Resume Next
     obj.Run "TEST" 'runs the macro
     msgbox Err.Number & "         " & Err.Description
end sub

the error i get is unknown runtime error and error number is 40040

Another question
Can i return a value to the vbscript through the macro..?

Thanks
 
 
Post #: 1
 
 RE: VBSCRIPT AND EXCEL MACRO - 3/30/2008 11:15:24 PM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
i unable to find the problem :(

(in reply to tools)
 
 
Post #: 2
 
 RE: VBSCRIPT AND EXCEL MACRO - 3/31/2008 12:57:20 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Which line gives you the error?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tools)
 
 
Post #: 3
 
 RE: VBSCRIPT AND EXCEL MACRO - 3/31/2008 2:35:52 PM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
The following line gives me an error

obj.Run "TEST" 'runs the macro

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/2/2008 2:22:15 PM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline

(in reply to tools)
 
 
Post #: 5
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 12:18:13 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
If the macro is held in the workbook then try this:


obj.Run "ThisWorkbook.TEST"

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tools)
 
 
Post #: 6
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 12:26:56 AM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
Nopes This  is not working :(
Now the macro is not running

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 12:34:54 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
"Now the macro is not running "

Does that mean that it was running before? Regardless, using the line that I posted along with the code that you posted ran a macro in my workbook just fine. I suspect that we need more information if it is not working for you.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tools)
 
 
Post #: 8
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 12:38:33 AM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
The macro was running previously but its not wrking now.

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 12:40:19 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Please post the exact code that you are running.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tools)
 
 
Post #: 10
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 2:54:22 PM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
The code i am running is same as above. Ill paste it again

sub openexcel()
     Dim obj
     Set obj = CreateObject("Excel.application")
     obj.Workbooks.Open "C:/Final templates/MyExcel.xls"
     obj.visible=true
     On Error Resume Next
     obj.Run "TEST"
     msgbox Err.Number & "         " & Err.Description
end sub

In the TEST macro, I am calling a function which would perform validations on the excel sheet.
I wanted to upload the excel sheet so that u could have a look at the macro but i am unable to do so.

This code does not throw an error when the macro consists of only a Msgbox but when I call the function that I have written it throws an error at the
obj.Run "TEST" line.

Thanks

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 5:03:07 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi tools,

so show the VBA macro code.

Regards

ehvbs

(in reply to tools)
 
 
Post #: 12
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/3/2008 5:07:36 PM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
The code is too long to paste it here. 

(in reply to ehvbs)
 
 
Post #: 13
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/7/2008 12:10:29 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Since it does not throw an error with a simple MsgBox and it does throw an error with your other code, then the problem would certainly appear to be in the macro not the VBScript. We can help you with that but not if you are not willing to post the code.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tools)
 
 
Post #: 14
 
 RE: VBSCRIPT AND EXCEL MACRO - 4/7/2008 2:21:50 PM   
  tools

 

Posts: 14
Score: 0
Joined: 3/27/2008
Status: offline
this is the code that i have written
this function is been called from the TEST macro which consists of a simple if else loop.
this function is further calling some other functions which i have not posted