VBScript not working on IE11 which has frames - vbscript

I have a code which is working perfectly fine in Excel VBA but when I am trying the same in VBscript, it is erroring out while looking for Frames on IE 11.
Name Value
Microsoft VBScript runtime error: Object doesn't support this property or method: 'ieobjbtn.GetElementsByTagName'
Dim objLink, ieobjbtn1, ieobjbtn
Set objCollection = objIE.Document.frames
Set ieobjbtn = objCollection("toolbar").Document.GetElementsByTagName("a")
'Script is giving mentioned error here
For Each objLink In ieobjbtn
If InStr(objLink.innerHTML, "xxxxx.gif") > 0 Then
objLink.Click
Wait_Webpage
Exit For
End If
Next

In the standard DOM the function is called getElementsByTagName - note the lowercase g at the start.
It wouldn't surprise me if older versions of IE supported case-insensitivity because that is normal in VBScript, but newer ones have withdrawn that feature. VBScript is rarely used in IE these days and is being dropped entirely in the Windows 10 version of IE.
''Update:''
The corrected version is:
Set objCollection = objIE.Document.frames
Set ieobjbtn = objCollection("toolbar").document.getElementsByTagName("a")

Related

Checking out data models in power designer with VBScript

Through a VBS code I need to check out some data models from the power designer.
The requirements are: Connect to the power designer repository, check out some data models. can anybody help me?
I found this code in SAP documentation, but when i execute it the following error appears.
Dim rc : Set rc = RepositoryConnection
'Check out model
Dim TargetModel
Set TargetModel = rc.FindChildByPath("MyFolder/MyPDM", PdRMG.Cls_RepositoryModel)
TargetModel.CheckOut()
Output "Checked"
The error messege:
Microsoft VBScript Runtime Error
Required object (0x800A01A8)
on line 5
As mentioned by the first comment, at least, verify the FindChildByPath return value:
Set TargetModel = rc.FindChildByPath("MyFolder/MyPDM", PdRMG.Cls_RepositoryModel)
if targetmodel is nothing then
output "nothing"
else
TargetModel.CheckOut()
Output "Checked out"
end if
Apart from that, the sample works for me, and opens the PDM I have checked in.

VBScript passing value by reference (VarPtr) to ActiveX function

I'm trying this:
Dim oApp
Dim iReturnedResult
Set oApp = CreateObject("Some.Application")
Set F_Ord = oApp.Documents.Open("Window 1", VarPtr(iReturnedResult))
The ActiveX control expects the second parameter to be a Long by reference.
This works perfectly well inside Excel VBA.
I can run this step by step, and see the result is returned like it should.
But, when I move this code to a VBS file and run it from the command line (CScript.exe), I get an error 800A000D, meaning it's the wrong type.
I have also tried creating an array instead, and tested with these commands, without any luck:
Set F_Ord = oApp.Documents.Open("Window 1", VarPtr(iReturnedResult(0)))
Set F_Ord = oApp.Documents.Open("Window 1", iReturnedResult(0))
Does anyone know how to pass a long variable by reference to an ActiveX control from VBScript?
The simple answer is VarPtr() is not supported by VBScript.
To my knowledge, there is no equivalent that allows you to pass a pointer to a variables memory address.
Useful Links
Visual Basic for Applications Features Not In VBScript

Use of SAPI Speech Recognition in a VBS Script?

I found this one-line example that allows to use the Windows SAPI Text-to-Speech feature in VBScript:
CreateObject("SAPI.SpVoice").Speak("This is a test")
I wonder if the SAPI Speech Recognition could be used in a VBScript program in the same easy way. When I seek for such information the tons of SAPI information that appear are related to C++, like the Microsoft SAPI site, or to Text-to-Speech in VBS. I tried to find documentation about the SAPI COM object Speech Recognition part that could be used in a VBScript, but found none.
Do you know if such a documentation exists? TIA
EDIT: Additional request added after the first answer was recevied
Although the first answer below provide a link to the SAPI COM object documentation, I want to attract your attention to a point in my question: "I wonder if the SAPI Speech Recognition could be used in a VBScript program IN THE SAME EASY WAY". The SAPI documentation is huge! I read several pages of it and I am completely lost... My goal is to recognize just a few single words, say 8 or 10, and show a different message in the screen each time that one of they was recognized; that is it! (The program should be a console application started via cscript). Is there a simple example of VBS code that achieve such thing? If the required code to program this solution needs to have several pages, then it is not the answer I am looking for...
Here is a working example of vbscript listening a wav file:
scriptRunning = true
Sub rc_Recognition(StreamNumber, StreamPosition, RecognitionType, Result)
Wscript.Echo "Reco: ", Result.PhraseInfo.GetText, ".", RecognitionType
End Sub
Sub rc_StartStream(StreamNumber, StreamPosition)
Wscript.Echo "Start: ", StreamNumber, StreamPosition
End Sub
Sub rc_EndStream(StreamNumber, StreamPosition, StreamReleased)
Wscript.Echo "End: ", StreamNumber, StreamPosition, StreamReleased
scriptRunning = false
End Sub
outwav = "C:\SOFT\projects\af2t\t.wav"
Const SAFT22kHz16BitMono = 22
Const SSFMOpenForRead = 0
set sapiFStream = CreateObject("SAPI.SpFileStream")
sapiFStream.Format.Type = SAFT16kHz16BitMono
sapiFStream.Open outwav, SSFMOpenForRead
MsgBox "A SpeechLib::ISpRecoContext object will be created"
Const SGDSActive = 1
Set rct = WScript.CreateObject("SAPI.SpInProcRecoContext", "rc_")
Set rgnz = rct.Recognizer
Set rgnz.AudioInputStream = sapiFStream
Set rcGrammar = rct.CreateGrammar
'rcGrammar.DictationLoad
rcGrammar.DictationSetState SGDSActive
i = 0
while scriptRunning and i < 100
WScript.Sleep(50)
i = i + 1
wend
MsgBox "A SpeechLib::ISpRecoContext object has been created"
The magical part of the code is this line (the "rc_" prefix param allows events to be caught by the subs):
Set rct = WScript.CreateObject("SAPI.SpInProcRecoContext", "rc_")
The recorded text in the t.wav file I used for testing has been generated with SAPI.SpVoice::Speak and MS-David voice ;-)
I spent 10 days figuring out how to write this script. Microsoft is removing documentation about automation, COM, old style scripts, etc. A shame.
So, this works in dictation mode reading a wav file. But I couldn't correct it to make it work in live dictation mode (i.e. using the microphone as direct input). Any help appreciated for this. Thanks.
EDIT: direct/live dictation mode solved. If interested I share the vbscript code.
EDIT2: text sample spoken in the wav: Hello world. This is a talk about gear tooth profile using a circle involute.
Console output from the vbscript
C:\SOFT\projects\af2t>cscript r.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. Tous droits réservés.
Start: 1 0
Reco: Hello world . 0
Reco: this is a talk about gear to the profile using a circle invalid . 0
End: 1 195040 -1
C:\SOFT\projects\af2t>
Yes. Look at the SAPI Automation Overview; it will tell you all about the late-bound COM interfaces and objects available to VBScript.

Lotus Notes - lotusscript: shell function: illegal function call

I have a problem: I want to run a file from lotusscript code:
Dim result As Integer
result = Shell("D:\testF.dsx", 1)
And I get the following error: Illegal function call.
If I want to execute it from formula it works:
#Command([Execute]; "D:\\testF.dsx")
Thanks a lot!
I had the same problem with the shell function in lotus script with PDF files. And my workaround is to use the windows scripting host to launch the file. I am pretty sure this will solve your problem too.
Set objShell = CreateObject("WScript.Shell")
returnValue = objShell.Run("d:\testF.dsx", 3, false)enter code here
It is not possible to "Execute" a Textfile. usually there is no "run" function defined for dsx- files.
You could do it like:
Dim result as Integer
result = Shell("notepad.exe D:\testF.dsx", 1)
Or find out, which program is linked to dsx (via registry) and execute the corresponding exe with filename as Parameter. If the filename contains spaces, then it has to be enclosed:
Dim result as Integer
result = Shell({notepad.exe "D:\testF.dsx"}, 1)
And reading your last question this approach for sure is NOT the right for your request. You have to use "open" in order to process files... Like Per Hendrik told you in his response.
I had similar problems passing parameters to Outlook.
On some windows machines, this #Formula worked perfectly:
#Command([Execute]; "Outlook.exe"; "/recycle")
On Windows Terminal Servers, it caused Outlook to be unable to parse the "/recycle"
The Shell-command from LotusScript wasn't even able to locate the Outlook.exe, as it was not in the PATH.
Ralf's code helped me in this respect. The "WScript.Shell" seems able to interact with Windows registry settings. Anyway, here is the code that works for activating an open Outlook window.
Dim objShell, returnValue
Set objShell = CreateObject("WScript.Shell")
returnValue = objShell.Run("outlook.exe /recycle", 3, False)

Error 91 using CreateObject on XP machines

I have an old VB6 app that I've distributed to several users running XP, Windows 7 and Windows 8. The following code is throwing an Error 91 ""Object variable or With block variable not set".
Const ssfPERSONAL = 46 'set directory to the common Documents folder
Dim strMyDocsPath As String 'stores common docsPath
On Error GoTo ErrorHandler
strMyDocsPath = CreateObject("Shell.Application").NameSpace(ssfPERSONAL).Self.Path
Specifically, the last line is the issue. I want strMyDocsPath to point to the common documents folder on the user machine. It works fine in Windows 7 and 8, but not on XP machines except the XP development machine where it runs without a hitch.
On the problem computers, I have tried re-registering scrrrun.dll and got a message it registered successfully. I tried downloading and installing the VB6 distributable SP6 files and still get the error. I have searched several forums and just can't figure it out. Any ideas?
It is usually useful to un-lump complex one-liners in one call per line fashion when debugging such kind of an error:
Dim DebugObj1 As Object
Dim DebugObj2 As Object
Dim DebugObj3 As Object
Set DebugObj1 = CreateObject("Shell.Application")
Debug.Print "1: " & CStr(DebugObj1 Is Nothing)
Set DebugObj2 = DebugObj1.NameSpace(ssfPERSONAL)
Debug.Print "2: " & CStr(DebugObj2 Is Nothing)
Set DebugObj3 = DebugObj2.Self
Debug.Print "3: " & CStr(DebugObj3 Is Nothing)
strMyDocsPath = DebugObj3.Path
Debug.Print strMyDocsPath
After that it is easier to spot what call doesn't return useful object, exactly. In your case it is most likely .NameSpace(ssfPERSONAL).
I was able to reproduce your problem in Windows XP SP3 if Shared Documents are disabled. There are many ways to disable them. See this, for example: http://www.howtogeek.com/howto/windows/how-to-remove-shared-documents-icon-from-my-computer-in-windows-xp/
As a side note, ShellSpecialFolderConstants.ssfPersonal is actually 0x05, see MSDN. The value 46 (or 0x2e) you use is CSIDL_COMMON_DOCUMENTS which indeed translates to Common Documents folder like C:\Documents and Settings\All Users\Documents. Probably, it is not the very best practice to use misleading naming.

Resources