I'm still learning MS word VBA equivalents in PB, to date the only one I can't get working cleanly is the "end of function" cleanup after opening an existing document.
In the code below the line "oWordDoc = NOTHING" fails, almost implying that the OBJECT does not exists, yet the document referenced opens and closes normally and can be manipulated (code not shown) while open with no problems.
Any comments much appreciated.
TIA
Ian B
In the code below the line "oWordDoc = NOTHING" fails, almost implying that the OBJECT does not exists, yet the document referenced opens and closes normally and can be manipulated (code not shown) while open with no problems.
Any comments much appreciated.
TIA
Ian B
Code:
#COMPILER PBWIN 9 #COMPILE EXE #DIM ALL ' oWord.inc CONTAINS THE MS WORD INTERFACE DEFINITIONS CREATED WITH THE PBCOM BROWSER #INCLUDE "oWord.inc" ' MAIN APPLICATION ENTRY POINT FUNCTION PBMAIN() CALL WordDemo END FUNCTION FUNCTION WordDemo AS LONG LOCAL oWordApp AS Int__Application ' Application Interface LOCAL oWordDoc AS Int__Document ' Document Interface LOCAL oWordSel AS Selection ' Selection Interface LOCAL oWordFont AS Int__Font ' Font inteface LOCAL sDocPath AS STRING ' Utility for various paths LOCAL vDoc AS VARIANT ' Utility for various document names LOCAL sText AS STRING ' Utility for various text items LOCAL vUtility AS VARIANT ' Utility variant ' OPEN AN INSTANCE OF WORD oWordApp = NEWCOM $PROGID_Application ' OPEN SUCCESSFUL? IF ISFALSE ISOBJECT(oWordApp) THEN MSGBOX "Unable to open or start MSWORD!" EXIT FUNCTION END IF ' MAKE WORD VISIBLE AND SHOW IN NORMAL STATE oWordApp.Visible = 1 oWordApp.WindowState = %wdWindowStateNormal ' OPEN AN EXISTING DOCUMENT sDocPath = UCODE$("C:\PBWin90\Samples\Com\Word\") '<<<< CHANGE TO SUIT oWordApp.ChangeFileOpenDirectory (sDocPath) vDoc="IansTest.doc" '<<<< CHANGE TO SUIT oWordDoc = oWordApp.Documents.Open(vDoc) IF ISFALSE ISOBJECT(oWordDoc) THEN MSGBOX "MSWORD was not able to open document." GOTO Terminate END IF ' TEST CODE GOES HERE MSGBOX "About to close" vUtility = %wdDoNotSaveChanges oWordApp.Documents.Close vUtility ' CLOSE ALL INTERFACES TERMINATE: oWordApp.Quit oWordSel = NOTHING oWordDoc = NOTHING '<<<< CODE FAILS HERE, IF COMMENTED OUT CODE FAILS ON END FUNCTION oWordApp = NOTHING END FUNCTION
Comment