The initial starting point is different. VBA is usually hosted by another application, which provides a set of built-in objects; for example, if your VBA is hosted in Word, you'll have access to the Word Application
which refers to the currently running Word application. In VBS, you have to either create a new Application object and save it in a variable:
Dim wdApp
Set wdApp = CreateObject("Word.Application")
or get a reference to an already running Word Application:
Set wdApp = GetObject(,"Word.Application")
Once you've done that, the code between them is virtually interchangeable:
Dim wdDoc
Set wdDoc = wdApp.Open("pathodocument.docx")
Bear in mind that in VBA variables can have a type. Instead of the previous variable declaration (
Dim wdDoc
), in VBA you can see this:
Dim wdDoc As Word.Document
'alternatively:
'Dim wdDoc As Document
Also, VBA generally has access to enum constants, such as wdFormatDocument
. In VBScript, you can either define the constants manually:
Const wdFormatDocument = 0
Or use the value of the constants directly:
wdApp.ActiveDocument.SaveAs2 FileName:="as90520.doc", FileFormat:= 0
Reference for the Word object model can be found
here.
As far as your specific question goes,
ActiveDocument
is a property of an
Application
object, (see
here). So in VBS, the corresponding code might look something like this:
Dim wdApp
Set wdApp = CreateObject("Word.Application")
'When you open Word from the Start menu, it automatically adds a blank document for you
'When manipulating Word in a program, we need to do this by hand
'Generally we would store this in a variable, but we don't need to store it in order
'to use the ActiveDocument property; it just has to exist
wdApp.Documents.Add
'copied and pasted from before
wdApp.ActiveDocument.SaveAs2 FileName:="as90520.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=0