|
|
SampleVbsOleAutomationFrom $1Table of contents[MISSING]' Kevin's all-purpose VBS (Windows Scripting) example
Dim WSHShell
Dim Args
Dim ArgList
Dim msword
'******************************************************
' Example showing how to obtain command line arguments
'******************************************************
msgbox "hello"
set Args = WScript.Arguments
For i = 0 to Args.Count - 1
ArgList = ArgList &i &":"&Args(i) & chr(13)
Next
MsgBox "You passed this many arguments on the command line: " & Args.Count & chr(13) & " and here they are:" & chr(13) & ArgList
'******************************************************
' Example showing how to automate Microsoft Word
'******************************************************
Const VB5 = False
Const wdLine = 5
Const wdPasteDefault = 0
' The commented-out lines work in the VB IDE but not as VBS
' Dim msword As Word.Application
' Set msword = CreateObject("Word.Application")
Set msword = WScript.CreateObject("Word.Application")
msword.Visible = TRUE ' Helpful when debugging to be able to SEE what happens
Call msword.Documents.Add ' Create a new Word document
Call msword.Selection.TypeText("This is line 1.") ' same as typing at the keyboard
Call msword.Selection.TypeParagraph ' Press ENTER
Call msword.Selection.TypeText("This is line 2.")
Call msword.Selection.TypeParagraph
Call msword.Selection.TypeText("This is line 3.")
Call msword.Selection.TypeParagraph
Call msword.Selection.MoveUp(wdLine, 2, False) ' Move up 2 lines
Call msword.Selection.MoveDown(wdLine, 1, True) ' Move down 1 line while holding SHIFT (select text in one line)
Call msword.Selection.Copy
Call msword.Selection.MoveDown(wdLine, 2, False)
Call msword.Selection.PasteAndFormat(wdPasteDefault)
Call msword.Selection.MoveUp(wdLine, 2, False)
Call msword.Selection.MoveDown(wdLine, 1, True)
MsgBox ("Currently selected text is:" + msword.Selection.Text)
Call msword.Quit(false) ' False says not to save the document
Tags:
none |