Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB Error "object required"

Tags:

vbscript

I'm getting an "object required" error on line 54, the last line, when I run the following script. What is wrong?

 Option Explicit
Dim cmdString, g_strHostFile, filepath, flexnetpath, importcmd, dtmToday, dtmYesterday, dtmFileDate, param1, param2, param3, i4path, objFSO, objTextStream, g_strComputer, WshShell
'Initialize global constants and variables.
Const FOR_READING = 1
g_strHostFile = "D:\dataimports\LUM_servers.txt"
i4path = "C:\IFOR\WIN\BIN\i4blt.exe"
filepath = "D:\DataImports\"
flexnetpath = "C:\Program Files (x86)\Flexnet\Manager\Admin"
importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath
dtmToday = Date()
dtmYesterday = Date() - 1
dtmFileDate = Year(Date) & padDate(Month(Date)) & padDate(Day(Date))
param1 = "-r1 -e2,4 -n "
param2 = " -v 'Dassault Systemes' -b "
param3 = " -g "
WScript.Echo "i4Path: " & i4path
WScript.Echo "FilePath: " & filepath
WScript.Echo "flexnetpath: " & flexnetpath
WScript.Echo "importcmd: " & importcmd
WScript.Echo "dtmToday: " & dtmToday
WScript.Echo "dtmYesterday: " & dtmYesterday
WScript.Echo "dtmFileDate: " & dtmFileDate

'Read LUM Server Names from text file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(g_strHostFile) Then
  Set objTextStream = objFSO.OpenTextFile(g_strHostFile, FOR_READING)
Else
  WScript.Echo "Input file " & g_strHostFile & " not found."
  WScript.Quit
End If
'Loop through list of computers and perform tasks on each.
Do Until objTextStream.AtEndOfStream
  g_strComputer = objTextStream.ReadLine
WScript.Echo "Processing Server: " & g_strComputer
Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl"
WScript.Echo "Processing Command: " & cmdString
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmdString"
Loop
objTextStream.Close
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Processing Bulk Import: " & importcmd
WshShell.Run "importcmd"

Function padDate(intNumber)
 if intNumber <= 9 Then
  padDate = "0" & CStr(intNumber)
 Else
  padDate = CStr(intNumber)
 End If
End Function
like image 762
ChuckO Avatar asked Jul 16 '10 14:07

ChuckO


People also ask

What does error object required mean in VBA?

The “Object required” means object data type reference needs to be accurate. When the Option Explicit word is unenabled in the coding, we will get an “Object Required” error for misspelled variable words. If Option Explicit is enabled, we will get the variable not defined error for misspelled variable words.

How do I fix object required error 424?

The simplest ways to fix the problem is as follows: Locate the offending line of code (if not highlighted, use debug mode) Identify whether you've referenced any objects which aren't declared. Look for any of the functions which may be causing an error and identify they are called correctly (with the correct syntax)

What is run time error 438 in VBA?

When you are trying to use a method/property that does not belong to the object. For instance, if you have a Workbook object and try to access the Range property, it will give you the 438 error since the Range property belongs to the Sheets object.


2 Answers

Object required is raised when you have a statement like Set x = y where x is not an object type, but is instead an simple type (Integer, Double, Date, etc. ). I think the line

Set cmdString = i4path & param1 & g_strComputer & param2 & ...

is causing the error, and I think all you have to do is remove the Set statement. I think strings do not derive from Object and thus do not need the Set statement.

like image 61
John Alexiou Avatar answered Nov 05 '22 07:11

John Alexiou


There are a few problems, I think.

 importcmd = flexnetpath & "flexnet bulkimport -uadmin -padmin -f" & filepath

You probably need some spaces:

 importcmd = flexnetpath & " flexnet bulkimport -uadmin -padmin -f " & filepath

Set is only used with objects, not strings, so it should be removed from this line:

 Set cmdString = i4path & param1 & g_strComputer & param2 & dtmYesterday & param3 & dtmToday & filepath & g_strComputer & "_" & dtmFileDate & "_lum.lrl"

I am fairly sure you either mean

 WshShell.Run importcmd

Or

 WshShell.Run """" & importcmd & """"
like image 30
Fionnuala Avatar answered Nov 05 '22 07:11

Fionnuala