0

How to use alias in VBScript? I am trying following code:

AliasesExample
Sub AliasesExample
  Dim AliasObj
  ' Obtains the object that corresponds to the Notepad main window
  Set AliasObj = Aliases.notepad.wndNotepad
  ' Checks whether the specified window exists
  If AliasObj.Exists Then
    ' Enters text in the Notepad editor
    AliasObj.Keys("Hello, world.")
  Else
    Log.Error("Notepad is not running.")
  End If
End Sub

but getting the following error:

object required: 'Aliases'
RedLeo
  • 127
  • 3
  • 10
  • You need to add a bit more code. Show what Aliases is Dim'd as, what it's been set to. At the moment I have no idea what you're trying to do. – simon at rcl Apr 11 '14 at 07:05
  • Question is updated as per your requirement. Now this is complete code. – RedLeo Apr 11 '14 at 07:10
  • Thanks, but what is Aliases? It's not something built in to Excel, so what is it? I would expect it to be null from the code you've shown so Aliases.notepad.wndNotepad could error if it is. And indeed the error says that Aliases is null. So what is it supposed to be? – simon at rcl Apr 11 '14 at 08:34
  • @Helen - thanks! I'll bow out here then, as I've never heard of it. – simon at rcl Apr 11 '14 at 08:43
  • 1
    @simon: Aliases is a class in Visual Basic to use "alias" (Indicates that an external procedure has another name in its DLL) and my question is "How to use aliases in VBScript?" as I need it in .vbs file! – RedLeo Apr 11 '14 at 09:48
  • @Helen: I also want to say you same thing as above with some addition; "PLEASE DO NOT EDIT ANY QUESTION, IF YOU ARE NOT SURE WHAT IS BEING ASKED!", at least confirm one time or ask for details if you are not understanding what an user is asking for. – RedLeo Apr 11 '14 at 09:53
  • @Helen:I know my English is not so good but the basic essence of this web site is to facilitate by answering the all kind of questions and not only correcting grammatical or spelling mistakes. – RedLeo Apr 11 '14 at 09:58
  • @RedLeo: Sorry. The code in your question is a TestComplete test script (not Visual Basic or WSH VBScript), so I assumed your question is about TestComplete. Please add the info from your comment (`Aliases is a class in Visual Basic to use "alias" (Indicates that an external procedure has another name in its DLL)`) to make it clear what you're looking for. – Helen Apr 11 '14 at 10:04
  • @Helen: Its OK, but I mentioned "VBS" in title of this question. :P – RedLeo Apr 11 '14 at 10:08
  • Could you please elaborate some more on what you are trying to do? What kind of function do you want to call from your VBScript - COM object method, function from another VBScript file, DLL/WinAPI function, etc? VBScript doesn't have the concept of aliases per se, so we need more details to suggest the solution. – Helen Apr 11 '14 at 10:19
  • Do you mean `Alias` as in Visual Basic's `Declare [Sub | Function] name Lib libname [Alias aliasname]` statement? – Helen Apr 11 '14 at 10:23
  • 1
    Yes exactly "Visual Basic's `Declare [Sub | Function] name Lib libname [Alias aliasname]` statement" – RedLeo Apr 11 '14 at 10:30

1 Answers1

0

VBScript and Windows Script Host do not support calling DLL and Windows API functions, but there're some possible solutions:

  • You can call DLL functions that are exposed through COM objects:

    Set obj = CreateObject("Foo.Bar")
    Call obj.Method(Param1, Param2)
    
  • You may be able to call some DLL functions using rundll32 if the DLL and the function meet certain requirements.

    ' Open "Programs and Features" using the Control_RunDLL function from shell32.dll
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run "rundll32.exe shell32.dll Control_RunDLL appwiz.cpl,,0"
    

Other than that, you're out of luck.

So generally, you need a COM-callable wrapper for your DLL function to be able to use it from VBScript.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thank you, this is really helpful, Actually I am trying to change icon of application with my custom icon on taskbar (in windows 8) do you have any idea of this? please check my another question [Change Excel 2013 default Icon](http://stackoverflow.com/questions/22867644/change-excel-2013-default-icon) – RedLeo Apr 11 '14 at 11:39