find the column number in range RRS feed

  • Question

  • Hello

    I am developing this script (it is run as a separate .vbs)

    Set oWRD = CreateObject("Word.Application")

    Set fso = CreateObject("Scripting.FileSystemObject")

    oWRD.Visible = True


    owrd.Documents.Open "C:\tmp\test.doc"


    sFolder = "."

    Set NewFile = fso.CreateTextFile(sFolder&"\output.txt", True)

    Set oCel = owrd.ActiveDocument.Tables(15).Cell(1,1)  

    Do While Not (oCel Is Nothing)


    'MsgBox oCel.Range.Text

    Set oCel = oCel.Next







    It works fine, but I am not able to identify  the data from column 5 for each row.


    How can I add the column number to the output file so that I know what column the recorded data comes from?


    I tried to extract the column number from the Range properties but I get an error ...





    Saturday, January 7, 2012 5:42 AM


  • It would be better to explicitly refer to the row and column numbers using a loop:

    Dim oTable, row, col, cellLabel
    Set oTable = oWrd.ActiveDocument.Tables(15)
    For row = 1 To oTable.Rows.Count
        For col = 1 To oTable.Columns.Count 
            cellLabel = "Cell(" & row & "," & col & ") = "
            newfile.WriteLine(cellLabel & oTable.Cell(row,col).Range.Text)

    Also note: when posing code, use the Insert Code Block button

    • Marked as answer by tester476 Saturday, January 7, 2012 9:28 PM
    Saturday, January 7, 2012 3:56 PM