user2531887
user2531887

Reputation: 57

"Object Required" Error After Declaring Excel.Application object

I am receiving an "object required" error while writing a VBScript to run a macro outside of Excel. The code is below this message. After declaring xlApp = CreateObject("Excel.Application"), any attempted action on the xlApp object will throw the "object required" error.

Am I missing something in my declaration statement, or is there some sort of import/include statement I need to make?

Sub temp()

  Dim xlApp, xlBook
  Dim oShell: Set oShell = CreateObject("WScript.Shell")
  oShell.CurrentDirectory = "H:"
  MsgBox (oShell.CurrentDirectory)

  xlApp = CreateObject("Excel.Application")
  xlApp.Visible = True 'error is thrown here
  xlBook = xlApp.Workbooks.Open("H:\SW Tool Resources\test\tester.xlsm")
  MsgBox ("Success")

End Sub

Upvotes: 1

Views: 4508

Answers (1)

Andy G
Andy G

Reputation: 19367

You need to Set your object variable to the new instance of Excel:

Set xlApp = CreateObject("Excel.Application")

Upvotes: 4

Related Questions