Intrigued
02-11-2005, 08:45 PM
This is from a .bas file (Worm) that was apart of a demo from over at the powerBASIC forums:
'================================================= =============================
'
' oWord.bas example for PowerBASIC Console Compiler
' Copyright (c) 2002-2004 PowerBASIC, Inc.
' All Rights Reserved.
'
' Run a short demonstration of sending data to Microsoft Word 97.
'
' * Tested with Excel '97 with VBA installed *
'
'================================================= =============================
#COMPILE EXE
#DIM ALL
#INCLUDE "oWord.inc"
DECLARE SUB DisplayResult(msg AS STRING)
'------------------------------------------------------------------------------
' Main application entry point...
'
FUNCTION PBMAIN()
DIM oWordApp AS WordApplication ' Application Interface
DIM oWordDoc AS WordDocument ' Document Interface
DIM oWordSel AS WordSelection ' Selection
DIM vBool AS VARIANT
DIM vText AS VARIANT
DIM vFile AS VARIANT
DIM vFileFmt AS VARIANT
DIM vVnt AS VARIANT
DisplayResult "About to Open MSWORD..."
' Open an instance of MSWORD
SET oWordApp = WordApplication IN "Word.Application"
IF ISFALSE ISOBJECT(oWordApp) THEN _
SET oWordApp = NEW WordApplication IN "Word.Application"
' Could MSWORD be opened? If not, terminate this app
IF ISFALSE ISOBJECT(oWordApp) THEN
DisplayResult "Unable to open or start MSWORD!"
EXIT FUNCTION
END IF
' Make MSWORD visible
DisplayResult "About to make MSWORD visible..."
LET vBool = 1
OBJECT LET oWordApp.Visible = vBool
' Get the current document count from the "documents collection"
DisplayResult "About to request the MSWORD document count..."
LET vVnt = 0
OBJECT GET oWordApp.Documents.Count TO vVnt
DisplayResult "MSWORD has " & FORMAT$(VARIANT#(vVnt)) & _
" File(s) loaded!"
' Add a document to the "documents collection", and obtain a reference
' to the document Interface for the new document
DisplayResult "Adding a new document to MSWORD..."
LET vVnt = 0
OBJECT CALL oWordApp.Documents.Add TO vVnt
IF OBJRESULT OR ERR THEN
DisplayResult "MSWORD was not able to start a new document." & $CR & _
"Please ensure MSWord and VBA are installed."
GOTO Terminate
END IF
SET oWordDoc = vVnt
' Get the current document count from the "documents collection"
' This should be one value higher than before
DisplayResult "Checking the MSWORD document count again..."
LET vVnt = 0
OBJECT GET oWordApp.Documents.Count TO vVnt
DisplayResult "MSWORD has " & FORMAT$(VARIANT#(vVnt)) & _
" File(s) loaded!"
' Get the Interface to the currect selection of the document
DisplayResult "About to obtain an interface to the current selection point..."
OBJECT GET oWordApp.Selection TO vVnt
SET oWordSel = vVnt
' Enter some text into the document at the selection position
DisplayResult "..and placing some text at that selection point..."
LET vText = "PowerBASIC controls Microsoft Word!"
OBJECT CALL oWordSel.TypeText(vText)
' Set a paragraph marker (end of paragraph)
OBJECT CALL oWordSel.TypeParagraph
' Another paragraph
LET vText = "COM client controls a COM server!"
OBJECT CALL oWordSel.TypeText(vText)
OBJECT CALL oWordSel.TypeParagraph
' Save the new document to disk
DisplayResult "About to save the document and close MSWORD..."
LET vFile = "Test.doc"
LET vFileFmt = %wdFormatDocument
OBJECT CALL oWordDoc.SaveAs(vFile, vFileFmt)
DisplayResult "All done! The COM automation stuff is pretty cool!"
Terminate:
' Close the current document and then close MSWORD completely
OBJECT CALL oWordApp.ActiveWindow.Close
OBJECT CALL oWordApp.Quit
' Close all of the Interfaces
SET oWordSel = NOTHING
SET oWordDoc = NOTHING
SET oWordApp = NOTHING
END FUNCTION
'------------------------------------------------------------------------------
' Compiler-independent helper function to display feedback and errors
'
SUB DisplayResult(msg AS STRING)
#IF %DEF(%PB_CC32)
PRINT msg
PRINT "Press a key...";
WAITKEY$
LOCATE ,1
#ELSE
MSGBOX msg, &H00001000& ' %MB_SYSTEMMODAL
#ENDIF
END SUB
Now, that code did what I have yet to fully achieve, add text too and at a certain position regardless of the version of M.S. Word installed such text in the open document.
I'll have a go soon again on the luaCOM-MSWord situation though.
Without doing my homework yet (d'oh), Worm, what is the .inc file(s) representing? Are they the project files? Or, is the .bas files the (as in base) project file(s)?
'================================================= =============================
'
' oWord.bas example for PowerBASIC Console Compiler
' Copyright (c) 2002-2004 PowerBASIC, Inc.
' All Rights Reserved.
'
' Run a short demonstration of sending data to Microsoft Word 97.
'
' * Tested with Excel '97 with VBA installed *
'
'================================================= =============================
#COMPILE EXE
#DIM ALL
#INCLUDE "oWord.inc"
DECLARE SUB DisplayResult(msg AS STRING)
'------------------------------------------------------------------------------
' Main application entry point...
'
FUNCTION PBMAIN()
DIM oWordApp AS WordApplication ' Application Interface
DIM oWordDoc AS WordDocument ' Document Interface
DIM oWordSel AS WordSelection ' Selection
DIM vBool AS VARIANT
DIM vText AS VARIANT
DIM vFile AS VARIANT
DIM vFileFmt AS VARIANT
DIM vVnt AS VARIANT
DisplayResult "About to Open MSWORD..."
' Open an instance of MSWORD
SET oWordApp = WordApplication IN "Word.Application"
IF ISFALSE ISOBJECT(oWordApp) THEN _
SET oWordApp = NEW WordApplication IN "Word.Application"
' Could MSWORD be opened? If not, terminate this app
IF ISFALSE ISOBJECT(oWordApp) THEN
DisplayResult "Unable to open or start MSWORD!"
EXIT FUNCTION
END IF
' Make MSWORD visible
DisplayResult "About to make MSWORD visible..."
LET vBool = 1
OBJECT LET oWordApp.Visible = vBool
' Get the current document count from the "documents collection"
DisplayResult "About to request the MSWORD document count..."
LET vVnt = 0
OBJECT GET oWordApp.Documents.Count TO vVnt
DisplayResult "MSWORD has " & FORMAT$(VARIANT#(vVnt)) & _
" File(s) loaded!"
' Add a document to the "documents collection", and obtain a reference
' to the document Interface for the new document
DisplayResult "Adding a new document to MSWORD..."
LET vVnt = 0
OBJECT CALL oWordApp.Documents.Add TO vVnt
IF OBJRESULT OR ERR THEN
DisplayResult "MSWORD was not able to start a new document." & $CR & _
"Please ensure MSWord and VBA are installed."
GOTO Terminate
END IF
SET oWordDoc = vVnt
' Get the current document count from the "documents collection"
' This should be one value higher than before
DisplayResult "Checking the MSWORD document count again..."
LET vVnt = 0
OBJECT GET oWordApp.Documents.Count TO vVnt
DisplayResult "MSWORD has " & FORMAT$(VARIANT#(vVnt)) & _
" File(s) loaded!"
' Get the Interface to the currect selection of the document
DisplayResult "About to obtain an interface to the current selection point..."
OBJECT GET oWordApp.Selection TO vVnt
SET oWordSel = vVnt
' Enter some text into the document at the selection position
DisplayResult "..and placing some text at that selection point..."
LET vText = "PowerBASIC controls Microsoft Word!"
OBJECT CALL oWordSel.TypeText(vText)
' Set a paragraph marker (end of paragraph)
OBJECT CALL oWordSel.TypeParagraph
' Another paragraph
LET vText = "COM client controls a COM server!"
OBJECT CALL oWordSel.TypeText(vText)
OBJECT CALL oWordSel.TypeParagraph
' Save the new document to disk
DisplayResult "About to save the document and close MSWORD..."
LET vFile = "Test.doc"
LET vFileFmt = %wdFormatDocument
OBJECT CALL oWordDoc.SaveAs(vFile, vFileFmt)
DisplayResult "All done! The COM automation stuff is pretty cool!"
Terminate:
' Close the current document and then close MSWORD completely
OBJECT CALL oWordApp.ActiveWindow.Close
OBJECT CALL oWordApp.Quit
' Close all of the Interfaces
SET oWordSel = NOTHING
SET oWordDoc = NOTHING
SET oWordApp = NOTHING
END FUNCTION
'------------------------------------------------------------------------------
' Compiler-independent helper function to display feedback and errors
'
SUB DisplayResult(msg AS STRING)
#IF %DEF(%PB_CC32)
PRINT msg
PRINT "Press a key...";
WAITKEY$
LOCATE ,1
#ELSE
MSGBOX msg, &H00001000& ' %MB_SYSTEMMODAL
#ENDIF
END SUB
Now, that code did what I have yet to fully achieve, add text too and at a certain position regardless of the version of M.S. Word installed such text in the open document.
I'll have a go soon again on the luaCOM-MSWord situation though.
Without doing my homework yet (d'oh), Worm, what is the .inc file(s) representing? Are they the project files? Or, is the .bas files the (as in base) project file(s)?