Getting "Object Required" Error Message - Need Help !!!

S

sydneyluu

I have an Excel workbook (Automate_WTI.xls) with three sheets - Sheet1,
Sheet2 and Sheet3. I wrote some VBA code under the Auto_Open routine in
the module file so that it will execute automatically when the XLS is
loaded. The code in this routine performs three basic things:

1. Loads an Excel Add-In.
2. Makes calls to this add-in to retrieve data from an external database
over the WAN and populates the Sheets.
3. Sends output to a network printer

Then I wrote a VB6 frontend to call the above Workbook. My goal is to have a
VB wrapper, which loops through a network folder; processes each workbook it finds.
The end result is to setup one single VB EXE in Windows 2000 Task Scheduler
to execute at certain time. Here's the test VB code I have:

Private Sub Command1_Click()


Dim xl As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim apppath As String

apppath = App.Path & "\" & "Automate_WTI.xls"

Set xl = New Excel.Application
xl.Visible = True

Set wkb = xl.Workbooks.Open(FileName:=apppath)

wkb.RunAutoMacros xlAutoOpen

'wkb.Save
'wkb.Close
'xl.Quit
'Set wks = Nothing
'Set wkb = Nothing
'Set xl = Nothing

End Sub


The problem I am having is when I invoke the VB EXE, I can see it loads my
workbook but puts me in debug mode with an error on this line in Auto_Open
routine and the error message is "Object Required"

Application.Run "Login", strMyLogin, strMyPasswd <-- stops here in debug mode

The above line makes a call to the Add-In to login to the external database.

Can someone provide some help and explain to me what I need to fix this? My
Excel/VBA skill is limited but good in VB.

Thank you in advance!!!


Sydney Luu
(e-mail address removed)
 
J

Jim Cone

Sydney,

Try adding the add-in workbook name to the Application.Run call...
( note the exclamation point that separates the workbook name from the sub routine )

Application.Run "MyAddInName.xla!Login, strMyLogin, strMyPasswd"

Regards,
Jim Cone
San Francisco, CA


-snip-
 
S

sydneyluu

Thanks for responding. This did not help fix the problem - still get
"Object Required" on that line.
 
C

Chip Pearson

Instead of 'Application', use the application object you created
with the Set New statement. E.g.,

xl.Run ....


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

Terry Shannon

Thanks for responding. This did not help fix the problem - still get
"Object Required" on that line.

Application methods are not available unless you create an application
object. Therefore you get the object required error. Check out the
help text on the application object. It will take you through the
process. I did this a couple of weeks ago. I think you need to create
your own class that uses the application object, then create an instance
of your new class at auto open. Then you will have the application
methods available to you.

Terry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top