Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The initial starting point is different. In VBA, you have a set of built-in objects, such as 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:</p> <pre><code>Dim wdApp Set wdApp = CreateObject("Word.Application") </code></pre> <p>or get a reference to an already running Word Application:</p> <pre><code>Set wdApp = GetObject(,"Word.Application") </code></pre> <p>Once you've done that, the code between them is virtually interchangeable:</p> <pre><code>Dim wdDoc Set wdDoc = wdApp.Open("path\to\document.docx") </code></pre> <p><hr> Bear in mind that in VBA variables can have a type. Instead of the previous variable declaration (<code>Dim wdDoc</code>), in VBA you can see this:</p> <pre><code>Dim wdDoc As Word.Document 'alternatively: 'Dim wdDoc As Document </code></pre> <p>Also, VBA generally has access to enum constants, such as <code>wdFormatDocument</code>. In VBScript, you can either define the constants manually:</p> <pre><code>Const wdFormatDocument = 0 </code></pre> <p>Or use the value of the constants directly:</p> <pre><code>wdApp.ActiveDocument.SaveAs2 FileName:="as90520.doc", FileFormat:= 0 </code></pre> <p><hr> Reference for the Word object model can be found <a href="http://msdn.microsoft.com/en-us/library/office/ff837519.aspx" rel="nofollow noreferrer">here</a>. <hr> As far as your specific question goes, <code>ActiveDocument</code> is a property of an <code>Application</code> object, (see <a href="http://msdn.microsoft.com/en-us/library/office/bb179183%28v=office.12%29.aspx" rel="nofollow noreferrer">here</a>). So in VBS, the corresponding code might look something like this:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload