Announcement

Collapse
No announcement yet.

PB9 COM Get ActiveDocument in MSWord

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

  • Ian Bayly
    replied
    That fixed my problem thanks José.
    Ian B

    Leave a comment:


  • José Roca
    replied
    Then use oWordApp = GETCOM $PROGID_Application.

    If the director word NEWCOM is specified, a new instance of a COM application is created. With GETCOM, an interface will be opened on an existing, running application, which has been registered as the active automation object for its class. With ANYCOM, the compiler will first try to use an existing, running application if available, or a new instance if not.

    Leave a comment:


  • Ian Bayly
    replied
    Again thanks José

    I think I need to get a reference to an existing word object and get the active document from that.
    A 3rd party product produces a Word document which is now sitting in the word window.
    The 3rd PP launches the exe I am producing which then carries out considerable manipulation within the document.
    You imply that I can only work with an existing document, which I take to mean an already saved doco, or a new empty doco.
    I could force the 3rd PP to save the doco as an rtf and then reopen but we are talking of 60 - 100 pages and the overhead of the rtf to word conversion when reopening the doco is not tenable.

    Does this extra explanation open any new avenues, or am I still blinded by the newness of PB?

    Ian B
    Last edited by Ian Bayly; 18 Mar 2009, 03:00 AM.

    Leave a comment:


  • José Roca
    replied
    You need first to load an existing document, or add a new one with oWordApp.Documents.Add. Otherwise, there is not any active document.

    Leave a comment:


  • Ian Bayly
    replied
    Thanks for that José, but it is a bit cryptic for me.
    Here is the code I'm using which opens a new instance of word and reports an error at IsObject(oWordDoc).
    Could you comment further please.

    Code:
    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 ietms
      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
    
    oWordDoc = oWordApp.ActiveDocument  '<<< Your suggestion
     ' MAKE WORD VISIBLE AND SHOW IN NORMAL STATE
      oWordApp.Visible = 1
      oWordApp.WindowState = %wdWindowStateNormal
      If IsFalse IsObject(oWordDoc) Then
                MsgBox "MSWORD was not able to get document."
                GoTo Terminate
              End If
    MsgBox "About to close"
    vUtility = %wdDoNotSaveChanges
    oWordApp.Documents.Close vUtility
    '   CLOSE ALL INTERFACES
    TERMINATE:
    oWordApp.Quit
    oWordSel = Nothing
    oWordDoc = Nothing  
    oWordApp  = Nothing

    Leave a comment:


  • José Roca
    replied
    Code:
    DIM oDoc AS Int__Document
    oDoc = oWordApp.ActiveDocument

    Leave a comment:


  • Ian Bayly
    started a topic PB9 COM Get ActiveDocument in MSWord

    PB9 COM Get ActiveDocument in MSWord

    Still struggling with some word functions due to my lack of COM knowledge.
    I have worked through creating new docs, opening existing docs but cannot get a handle on the active document in existing word object.
    Looking at the inc file I think I have to treat the active document as if it was an application, but all coding attempts have thus far failed.
    Any guidance much appreciated.

    Ian B
Working...
X