Re: Word.Document, wdGoToBookmark, Bad parameter error

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Michael Harris \(MVP\) (mikhar_at_mvps.org)
Date: 02/09/05


Date: Wed, 9 Feb 2005 09:55:25 -0800


> I couldn't find any documentation that revealed that syntax. Do you
> know of a reference anywhere that explains how to use the Word
> objects and methods with VBScript instead of with VBA or macros?

Your best bet is to then refer to the Office VBA documentation...

Documentation for Office object models is supplied with every copy of
Office. Start the Office application you're interested in. On the menu bar,
select Help/Contents and Index. In the contents, select Microsoft Visual
Basic Reference/Visual Basic Reference. This will bring up the VBA help
file.

When you read the help on the various objects, properties, methods, etc. you
have to keep in mind that it's written in the context of VBA hosted by a
specific VBA-enabled application, not VBScript. VBA is hosted "from the
inside" by the specific application. As the host, it automatically provides
things to the VBA code that aren't automatic when you automate an
application's object model "from the outside" using VBScript hosted by WSH.

The key items to remember:

--- No objects are automatically exposed to VBScript. You generally use an
explicit CreateObject to get an instance of an object to use as the "root",
usually the ".Application" object.

---In VBA that Application object and it's immediate interface members
(properties/methods) are automatically exposed. In VBScript you refer to the
Application object and it's properties/methods through the object variable
reference returned by the CreateObject.

---Named constants specific to the application aren't exposed. You can
either look them up and code them locally in the VBScript code as Const
variables, or you can use the .wsf file format and a <reference> element to
automatically expose them.

---VBA supports named argument syntax (e.g., ArgName:="argvalue") in method
calls. In WSH hosted VBScript, you have to code all arguments as positional
arguments since named argument syntax is not supported.

Once you understand the "VBA from the inside" vs "VBScript from the outside"
 issues and the fundamental differences between VBA and VBScript as separate
but similar languages, you should be able to mentally "port" VBA and even
full VB examples to VBScript.

A common trick scripters often use is recording a VBA macro within an Office
application while performing a task that they want to automate and then
porting the VBA macro code to VBScript.

-- 
Michael Harris
Microsoft.MVP.Scripting


Relevant Pages

  • Re: add Excel worksheet problem
    ... You have to rely on the VBA documentation that comes with Office apps. ... Automating Office applications externally via VBScript (or any other COM ... capable language) starts by creating a reference to the specific Office ... application while performing a task that they want to automate and then ...
    (microsoft.public.scripting.jscript)
  • Re: How can vbscript start an application like Excel with parameter?
    ... Automating Office applications externally via VBScript (or any other COM ... Your best bet is to then refer to the Office VBA documentation... ... Basic Reference/Visual Basic Reference. ... application while performing a task that they want to automate and then ...
    (microsoft.public.scripting.vbscript)
  • Re: Setting Word PageSetup with vbScript
    ... >> copied in vbscript code, ... > Your best source is the Office VBA documentation... ... > things to the VBA code that aren't automatic when you automate an ... > Application object and it's properties/methods through the object variable ...
    (microsoft.public.windows.server.scripting)
  • Re: Insert image to Excel programmatically
    ... If multiple pictures are going to be inserted ... Use the temp macro as a guide to create the VBScript ... > Your best bet is to then refer to the Office VBA documentation... ... > application while performing a task that they want to automate and then ...
    (microsoft.public.scripting.vbscript)
  • Re: Excdel and VBS
    ... Your best bet is to stick with the Office VBA documentation... ... application's object model "from the outside" using VBScript hosted by WSH. ... reference returned by the CreateObject. ... to record a VBA macro for the task you want to automate and then port the ...
    (microsoft.public.windows.server.scripting)