simple script

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
MacschedStudent
Junior Coder
Posts: 36
Joined: Fri Oct 12, 2007 5:55 pm
Location: federal way wa
Contact:

simple script

Post by MacschedStudent » Fri Oct 12, 2007 6:39 pm

Guys look at this simple code:





ExcelFile = "test.xls"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.workbooks.open(ExcelFile)





Thats it! thats the entire code and yet I get the "object required objExcel" how is that possible. I'm setting the object before I call on it. Any ideas..??

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Oct 12, 2007 8:32 pm

I assume you're not trying to run VBScript as Macro Scheduler Script. If you are, look up VBSTART, VBRun and VBEVal in help. Also the file "test.xls" needs a path. I put test.xls in the root of C: (windows XP) and the following opens the file for me.

There is no Excel GUI available but looking in Task Manager, I can see that excel is running.

Code: Select all

VBSTART
Sub OpenExcel
ExcelFile = "c:\test.xls"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.workbooks.open(ExcelFile)
End Sub
VBEND

VBRun>OpenExcel

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Oct 12, 2007 8:34 pm

If you want to make Excel visible modify as follows:

Code: Select all

VBSTART
Sub OpenExcel
  ExcelFile = "c:\test.xls"
  Set objExcel = CreateObject("Excel.Application")
  objExcel.Visible = true
  Set objWorkbook = objExcel.workbooks.open(ExcelFile)
End Sub
VBEND

VBRun>OpenExcel
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MacschedStudent
Junior Coder
Posts: 36
Joined: Fri Oct 12, 2007 5:55 pm
Location: federal way wa
Contact:

Post by MacschedStudent » Sat Oct 13, 2007 5:35 am

thanks marcus I had not put the code in MacSched yet I was simply confused as to why it would not work as a vbs file. Thanks again!!

MacschedStudent
Junior Coder
Posts: 36
Joined: Fri Oct 12, 2007 5:55 pm
Location: federal way wa
Contact:

Post by MacschedStudent » Sun Oct 14, 2007 8:59 pm

Marcus, I placed test.xls onto C drive and pasted your entire code into the editor and compiled in Msched and I still get the same response.


"line 5 Column2 object required objExcel" could the excel server be damaged somehow???

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts