Vbs ошибка требуется объект string

I have the code

set WshShell = CreateObject("WScript.Shell")
Set ie = CreateObject("InternetExplorer.Application")
ie.Offline = True
ie.Navigate "about:blank"
ie.Height     = 200
ie.Width      = 425
ie.MenuBar    = False
ie.StatusBar  = False
ie.AddressBar = False
ie.Toolbar    = False
ie.Visible = True
WshShell.Run "%windir%\notepad.exe"
WshShell.AppActivate "Notepad"
WScript.Sleep 3000
set a = WshShell.SendKeys("a") & Wscript.Sleep("100")
a

It does type «a» in notepad, but then it gives the error,» Object Required: ‘[string: «»]’ » and it will prevent any code after it from running.

If anyone knows how to fix this and prevent it in the future that would be great.

asked Mar 21, 2017 at 3:52

EternalMonologue's user avatar

1

You’re trying to assign something to a variable as an object that isn’t an object (Set a = ...). Don’t do that. Neither SendKeys() nor Sleep() return output, so there’s no point in assigning that non-output anyway. Or in concatenating it (you’re probably confusing the VBScript string concatenation operator & with the batch command chaining operator &).

Change this:

Set a = WshShell.SendKeys("a") & WScript.Sleep("100")

into this:

WshShell.SendKeys("a")
WScript.Sleep(100)

and the problem will disappear.


If you’re trying to implement a procedure that you can invoke as a shorthand, that would be done e.g. like this:

Sub k
  WshShell.SendKeys("a")
  WScript.Sleep(100)
End Sub

k  'sends keystroke "a" and waits 100 ms

or like this, if you want it parametrized:

Sub k(keys)
  WshShell.SendKeys(keys)
  WScript.Sleep(100)
End Sub

k "b"  'sends keystroke "b" and waits 100 ms

answered Mar 21, 2017 at 9:19

Ansgar Wiechers's user avatar

Ansgar WiechersAnsgar Wiechers

193k25 gold badges256 silver badges330 bronze badges

3

VBScript has data (sub) types. Besides simple (sub) types like Strings:

>> x = "blank"
>> WScript.Echo VarType(x), TypeName(x)
>>
8 String

there are Objects:

>> Set y = New RegExp
>> WScript.Echo VarType(y), TypeName(y)
>>
9 IRegExp2

To assign an object to a variable, you need Set, to compare objects, you need Is. Simple (non-object) values have their own comparison operator.

To compare a string against another:

>> WScript.Echo CStr(x = "blank"), CStr(x = "object")
>>
True False

Trying to use a simple value ‘as if it were an object’, throws an «object required» error:

>> Set z = "blank"
>>
Error Number:       424
Error Description:  Object required
>> WScript.Echo CStr(x Is x)
>>
Error Number:       424
Error Description:  Object required

Read A Whole Lot Of Nothing.

Set objPath = objFSO.BuildPath(CurrentDirectory, """new 1.cmd""")

У вас есть 3 ошибки в этом утверждении:

  • Вложенные двойные кавычки в """new 1.cmd""" сделать их частью действительного имени файла, что недопустимо. FileSystemObject методы могут обрабатывать пути с пробелами сами по себе, без дополнительных двойных кавычек. Вам нужно добавить двойные кавычки при прохождении пути к Run метод, хотя.
  • CurrentDirectory является собственностью WshShell объекты, а не встроенная переменная.
  • BuildPath Метод возвращает строку, а не объект, поэтому вам нужно удалить Set ключевое слово.

Это будет делать то, что вы хотите:

objPath = objFSO.BuildPath(objShell.CurrentDirectory, "new 1.cmd")
...
objShell.Run """" & objPath & """", 1, True

Dim oFile, oFilesys,oFileADVFEEMAA, oFileADVFEE
set oFilesys = CreateObject(«Scripting.FileSystemObject»)
wscript.echo «Line 2»
set oFileADVFEEMAA = oFilesys.GetFile («D:\NDM\Upload\BPS_JE\BPSFile\ADVFEEMAA.txt»)
wscript.echo «Line 3»
set oFileADVFEE= oFilesys.GetFile («D:\NDM\Upload\BPS_JE\BPSFile\ADVFEE.txt»)
wscript.echo «Line 4»
set oFile = oFilesys. GetFileName(oFileADVFEE.Name) –“ Microsoft VBScript runtime error: Object required: ‘[string: «ADVFEE.txt»]’”—errror here
wscript.echo «File Name “ & oFile
if oFileADVFEEMAA.Size = 1 Then
oFileADVFEEMAA.Delete
wscript.echo «ADVFEEMAA file is Deleted.»
wscript.quit 0
Else
If oFileADVFEEMAA.Size>1 and oFileADVFEE.Size >1 Then
wscript.echo «Problem 2 ADVFEE files with data.»
wscript.quit 1
Else
If oFileADVFEEMAA.Size>1 and oFileADVFEE.Size = 1 Then
oFileADVFEE.Delete
oFileADVFEEMAA.Name = oFile
script.echo » ADVFEEMAA renamed to » & oFileADVFEEMAA.Name
wscript.quit 0
End If
End If
End If

What I have tried:

Dim oFile, oFilesys,oFileADVFEEMAA, oFileADVFEE
set oFilesys = CreateObject(«Scripting.FileSystemObject»)
wscript.echo «Line 2»
set oFileADVFEEMAA = oFilesys.GetFile («D:\NDM\Upload\BPS_JE\BPSFile\ADVFEEMAA.txt»)
wscript.echo «Line 3»
set oFileADVFEE= oFilesys.GetFile («D:\NDM\Upload\BPS_JE\BPSFile\ADVFEE.txt»)
wscript.echo «Line 4»
set oFile = oFilesys. GetFileName(oFileADVFEE.Name) –“ Microsoft VBScript runtime error: Object required: ‘[string: «ADVFEE.txt»]’”—errror here
wscript.echo «File Name “ & oFile
if oFileADVFEEMAA.Size = 1 Then
oFileADVFEEMAA.Delete
wscript.echo «ADVFEEMAA file is Deleted.»
wscript.quit 0
Else
If oFileADVFEEMAA.Size>1 and oFileADVFEE.Size >1 Then
wscript.echo «Problem 2 ADVFEE files with data.»
wscript.quit 1
Else
If oFileADVFEEMAA.Size>1 and oFileADVFEE.Size = 1 Then
oFileADVFEE.Delete
oFileADVFEEMAA.Name = oFile
script.echo » ADVFEEMAA renamed to » & oFileADVFEEMAA.Name
wscript.quit 0
End If
End If
End If


Remove these lines:

set oFile = oFilesys. GetFileName(oFileADVFEE.Name) –" Microsoft VBScript runtime error: Object required: '[string: "ADVFEE.txt"]'"---errror here
wscript.echo "File Name " & oFile

and use the oFileADVFEE.Name directly:

wscript.echo "File Name " & oFileADVFEE.Name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

  • Home
  • VBForums
  • Visual Basic
  • ASP, VB Script
  • Object required : ‘[String: «xxxx»]

  1. Jul 10th, 2012, 10:29 AM


    #1

    foufou_qc is offline

    Thread Starter


    New Member


    Object required : ‘[String: «xxxx»]

    Hi What is my error?

    Code:

    Const ForReading = 1 
    Const ForWriting = 2 
    
    Set objArgs = Wscript.Arguments 
    
    If objArgs.Count <> 3 then
        Wscript.Echo "Manque des param�tres: Fichier ASCII, Valeur recherche puis Nouvelle valeur"
    End if 
    
    For I = 0 to objArgs.Count -1
    'rgs.Count - 1 
    WScript.Echo objArgs(I) 'v�rifie mes param�tres
        Select Case I
    	   Case 0 : Set FichierASCII = objArgs(I)
    	   Case 1 : Set ValeurRecherche = objArgs(I)
               Case 2 : Set NouvelleValeur = objArgs(I)
    	   Case Else : Wscript.Echo "trop de parametres:  Fichier ASCII, Valeur recherche puis Nouvelle valeur"
        End Select 
    Next
    
    
    
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.OpenTextFile(FichierASCII, ForReading) 
    
    strText = objFile.ReadAll 
    objFile.Close

    My first image is my parameter before set to FichierASCII. My second image is my error line 14 : Case 0 : Set FichierASCII = objArgs(I)

    Why?

    Thank’s a lot


  2. Jul 10th, 2012, 12:30 PM


    #2

    Re: Object required : ‘[String: «xxxx»]

    since the objArgs are strings, the variable shouldn’t be set….
    Set FichierASCII = objArgs(I)

    Set is only needed for objects… which isn’t what you’re dealing with here…

    it should be a simple assignment:
    FichierASCII = objArgs(I)

    -tg


  3. Jul 10th, 2012, 03:24 PM


    #3

    foufou_qc is offline

    Thread Starter


    New Member


    Smile Re: Object required : ‘[String: «xxxx»]

    Thank’s a lot,

    I remove SET command and I didn’t have error.

    Thank’s


  • Home
  • VBForums
  • Visual Basic
  • ASP, VB Script
  • Object required : ‘[String: «xxxx»]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Forum Rules


Click Here to Expand Forum to Full Width

Понравилась статья? Поделить с друзьями:
  • Vba excel ошибка 457
  • Vba excel ошибка 438
  • Vba excel ошибка 361
  • Vba excel обработчик ошибок
  • Vba excel обработка ошибок vba