Announcement

Collapse
No announcement yet.

PB8 vs PB9 - Opening an MSWord document

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB8 vs PB9 - Opening an MSWord document

    Most of my future PBCode will involve manipulating MSWord, but I'm off to a slow start.
    PB8 samples has an oWord.bas and if I add these few lines to this PB8 code, it will open the referenced document as expected.
    ~~
    LET vVnt = 0
    DIM vPath AS VARIANT
    DIM vDocs AS VARIANT
    vDocs="IansTest.doc"
    vPath="C:\PBWin90\Samples\Com\Word\"
    OBJECT CALL oWordApp.ChangeFileOpenDirectory (vPath) TO vVnt
    SET oWordDoc = vVnt
    LET vVnt = 0
    OBJECT CALL oWordApp.Documents.Open(vDocs)
    IF OBJRESULT OR ERR THEN
    DisplayResult "MSWORD was not able to Open a new document."
    GOTO Terminate
    END IF
    ~~
    Using the oWord.bas from PB9 samples and adding the code below doesn't generate errors but does not open the document.
    The oWord.inc shows ChangeFileOpenDirectory as needing a string and changing to a variant does not alter the issue.
    ~~
    DIM vDoc AS VARIANT
    DIM sPath AS STRING
    sPath ="C:\PBWin90\Samples\Com\Word\"
    oWordApp.ChangeFileOpenDirectory (sPath)
    vDoc="IansTest.doc"
    oWordApp.Documents.Open(vDoc)
    IF ISFALSE ISOBJECT(oWordDoc) THEN
    MSGBOX "MSWORD was not able to open document."
    GOTO Terminate
    END IF
    ~~
    If I comment out the PB9 code which adds a new document, then the Doc open will fail with an error returned from ISOBJECT

    Can anyone point me in the right direction please.

    TIA
    Ian B

  • #2
    If the parametrer is not a variant, but an string, you have to convert it to unicode.

    sPath = UCODE$("C:\PBWin90\Samples\Com\Word\")
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Thank you Jose, I assume this applies to any passing of any string. Certainly works as expected now.

      Ian B

      Comment

      Working...
      X