6 Replies Latest reply: Mar 26, 2012 5:17 PM by flipside RSS

Macro - Loop Through Table

cache.merrill

I need a sample macro that loops thorugh a table and reads out some values.  I can't find one.  

  • Macro - Loop Through Table
    flipside

    Hi,

     

     

    From API Guide.qvw ...

     

    set TableBox = ActiveDocument.GetSheetObject( "TB01" )

    for RowIter = 0 to TableBox.GetRowCount-1

        for ColIter =0 to TableBox.GetColumnCount-1

            set cell = TableBox.GetCell(RowIter,ColIter)

            msgbox(cell.Text)

        next

    next

     

    flipside

    • Macro - Loop Through Table
      ianmcgivern

      Hi flipside

       

      Where in the API did you get this? The Automation Examples sheet? If so, what search did you do on member?

      • Macro - Loop Through Table
        flipside

        Hi Ian,

         

        I'm working in QV10 and got it from ...

         

        Class = TableBox

        Member = GetCell

         

        ...  showing as introduced in 6.0x.

         

        flipside

        • Macro - Loop Through Table
          cache.merrill

          If I don't want to loop through each column but just get a value from one column how would i do that? 

           

          set TableBox = ActiveDocument.GetSheetObject( "tb_emails_to_send" )

              for RowIter = 0 to TableBox.GetRowCount-1   

                  set cell = ?

                  msgbox(cell.Text)   

              next

          • Macro - Loop Through Table
            Stephen Charles

            This code moves from column to column and row to row and keepings counting. It gets the value in the 16th spot in the loop and puts into the variable vValue and exits the sub routine.

            hths,

            Stephen

             

            sub ParetoCountInvValue1

            vCounter1 = 0

            vCounter2 = 0

            set table = ActiveDocument.GetSheetObject( "CH01" )

            for RowIter = 0 to table.GetRowCount-1

            for ColIter =0 to table.GetColumnCount-1

            set cell = table.GetCell(RowIter,ColIter)

            vCounter1 = vCounter1 + 1

            if vCounter1 = 16 then

            'msgbox ColIter

            'msgbox(cell.Text)

            set v = ActiveDocument.Variables("vValue")

            v.SetContent cell.Text,true

            exit sub

            else

            end if

             

            next

            next

            end sub

             

             

             

             

             

             

          • Macro - Loop Through Table
            flipside

            You just need to specify the column index (starting at zero for column 1) so looping through values in the first column would need...

             

                      set cell = TableBox.GetCell(RowIter,0)

             

            flipside