Announcement

Collapse
No announcement yet.

MS Word Insert table (PB9 - Word 2003)

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

  • Ian Bayly
    replied
    Dominic

    Thank you for your generous and comprehensive assistance.

    In summary my code line
    oWordTable = oWordTables.Add(oWordRange, 3, 3)
    should read
    oWordTable = oWordDoc.Tables.Add(oWordRange, 3, 3)

    Regards

    Ian B

    Leave a comment:


  • Dominic Mitchell
    replied
    The following is a sample that works.
    The names are different because it uses an include file that was generated by Phoenix.

    Code:
      LOCAL oWordApp     AS WordApplication   
      LOCAL oWordDoc     AS WordDocument      
      LOCAL oWordSel     AS WordSelection     
      LOCAL oRange       AS WordRange         
      LOCAL oWordTable   AS WordTable         
      LOCAL cRows        AS LONG
      LOCAL cCols        AS LONG
      LOCAL iRow         AS LONG
      LOCAL iCol         AS LONG
      DIM   sTable(10, 10) AS STRING
    
      ' Open an instance of MS Word
      oWordApp = NEWCOM $PROGID_WORDAPPLICATION12
    
      ' Make MS Word visible in for example normal show state
      oWordApp.Visible = 1
      oWordApp.WindowState = %WDWINDOWSTATENORMAL
    
      ' Add a document to the "documents collection", and obtain a reference
      ' to the document Interface for the new document
      oWordDoc = oWordApp.Documents.Add
    
      ' Get the Interface to the currect selection of the document
      oWordSel = oWordApp.Selection
    
      ' Enter some text into the document at the selection position
      oWordSel.TypeText(UCODE$("Favorite Foods:"))
      oWordSel.TypeText(UCODE$($CRLF))
      oWordSel.TypeText(UCODE$($CRLF))
    
      ' Create a table with 3 rows and 2 columns.
      oRange = oWordSel.Range
      cRows = 3
      cCols = 2
      oWordTable = oWordDoc.Tables.Add(oRange, cRows, cCols)
      oWordTable.Borders.OutsideLineStyle = %WDLINESTYLEEMBOSS3D
      oWordTable.Borders.InsideLineStyle = %WDLINESTYLESINGLE
      
      ' Fill in the first row with
      ' column header information
      sTable(1,1) = UCODE$("Food"            )
      sTable(1,2) = UCODE$("Type"            )
      sTable(2,1) = UCODE$("Apple"           )
      sTable(2,2) = UCODE$("Fruit"           )
      sTable(3,1) = UCODE$("Brussell Sprouts")
      sTable(3,2) = UCODE$("Veggie"          )
    
      FOR iRow = 1 TO cRows  
    
        FOR iCol = 1 TO cCols  
          oWordTable.Cell(iRow, iCol).Range.Text = sTable(iRow, iCol)
        NEXT iCol
    
      NEXT iRow
    
      MSGBOX "All done!"
    Last edited by Dominic Mitchell; 19 Aug 2009, 10:16 PM.

    Leave a comment:


  • José Roca
    replied
    The line LOCAL oWordRange AS RANGE brings up the word RANGE coloured blue. This implies that it is not a Word Range I am declaring but rather a KeyWord in PB..
    Wrong. Range is a secondary keyword for a couple of the ProgressBar statements, but other than becoming blue, it has no other effect in your case.

    Leave a comment:


  • Ian Bayly
    replied
    I'm still working with this and as an aid started a small cut of code in PB9/Win IDE (rather than the original Firefly) and this may have shown me my problem , but not the solution.
    The line LOCAL oWordRange AS RANGE brings up the word RANGE coloured blue. This implies that it is not a Word Range I am declaring but rather a KeyWord in PB.. I suspect if I could properly declare a Word Range it would then create the table.
    Again, any suggestions much appreciated.

    Ian B

    Leave a comment:


  • Ian Bayly
    started a topic MS Word Insert table (PB9 - Word 2003)

    MS Word Insert table (PB9 - Word 2003)

    I am assembling a word document and have come unstuck attempting to insert a table.
    The inc file has worked fine and I believe the problem is with my code. Below is a code snip showing my code along with a commented copy of the method from the inc file. The result is Word fails and wants to report a fault etc etc

    Any pointers much appreciated

    Ian B

    I guess the PB_xx in the method is because there is a potential conflict with a PB item.
    Code:
    Local oWordTable   As Table
    Local oWordTables  As Tables
    Local oWordRange   As Range
    '  Insert Table
    oWordRange = oWordsel.Range
    oWordTable = oWordTables.Add(oWordRange, 3, 3)
    'ADD <200> (BYVAL PB_Range AS Range, BYVAL NumRows AS LONG, BYVAL NumColumns AS LONG, OPT BYREF IN DefaultTableBehavior As VARIANT, Opt ByRef In AutoFitBehavior As VARIANT) As Table
Working...
X