3 Replies Latest reply: Dec 2, 2011 5:21 AM by Kamal Naithani RSS

    How to pick fields of a selected table using macro

    Rikab Kothari

      Hi,

       

      How to pick all the fields of a table using macro? For example, using the below macro we are able to pick the table name. we would like to pick all fields of the selected table as well. For your information we would like to pick automatically instead of adding the fields one by one.

       

      Can someone please help me out on this.

       

      Thanks,
      qvforum

        • How to pick fields of a selected table using macro
          Kamal Naithani

          Hi...but can you tell me that where you want all the table to be filled.

          In case you want to get the field in excel ...than you can apply simply as

           

           

          SUB xport2xl()

                    iRow=1

                    dim kost,i

                    kost =""

                    kost = "Sheet1"

                    SET xlApp = CreateObject("Excel.Application")

                    xlApp.Visible = True

           

                    SET xlWB = xlApp.Workbooks.Add

                    SET xlSheet = xlWB.Worksheets(1)

                    set obj = ActiveDocument.getsheetobject(ChartName)

           

                    xlSheet.Activate

                    xlSheet.Cells.Clear

           

                    SET txt = ActiveDocument.GetSheetObject("CH2637")

                    txt.CopyTableToClipboard TRUE

                    xlSheet.Cells(iRow,1).Select

                    xlSheet.Paste

           

                    WHILE NOT (IsEmpty(xlSheet.Cells(iRow,1)))

                              iRow = iRow + 2

                    WEND

           

                    SET txt1 = ActiveDocument.GetSheetObject("CH2635")

                    txt1.CopyTableToClipboard TRUE

                    xlSheet.Cells(iRow,1).Select

                    xlSheet.Paste

           

                    end sub

           

           

           

           

           

           

           

           

          SUB xport2xl2()

                    iRow=1

                    dim kost,i

                    kost =""

                    kost = "Sheet1"

                    SET xlApp = CreateObject("Excel.Application")

                    xlApp.Visible = True

           

                    SET xlWB = xlApp.Workbooks.Add

                    SET xlSheet = xlWB.Worksheets(1)

                    set obj = ActiveDocument.getsheetobject(ChartName)

           

                    xlSheet.Activate

                    xlSheet.Cells.Clear

           

                    SET txt = ActiveDocument.GetSheetObject("MB02")

                    txt.CopyTableToClipboard TRUE

                    xlSheet.Cells(iRow,1).Select

                    xlSheet.Paste

           

                    WHILE NOT (IsEmpty(xlSheet.Cells(iRow,1)))

                              iCol = iCol + 3

                    WEND

           

                    SET txt1 = ActiveDocument.GetSheetObject("MB03")

                    txt1.CopyTableToClipboard TRUE

                    xlSheet.Cells(iRow,1).Select

                    xlSheet.Paste

                    end SUb

           

           

          regards

          kamal

          • Re: How to pick fields of a selected table using macro
            Kamal Naithani

            Hi you can try this

            Sub Selection_bingo

            set f = ActiveDocument.Fields("MyField")

            set table = ActiveDocument.GetSheetObject("TB02(Tablebox)")

            for RowIter = 1 to table.GetRowCount-1

            for ColIter =0 to table.GetColumnCount-1

            set myvalues= table.GetCell(RowIter,ColIter)

            msgbox(myvalues.Text)

            ' f.select myvalues

            next

            next

            End Sub..

            hope this will help you

             

             

            or

             

            Sub CreateTable

             

            Set tb= ActiveDocument.Sheets("Main").CreateTableBox

            tb.AddField "FieldName1"

            tb.AddField "FieldName2"

             

            End Sub

             

             

            // This is code adding fileds for existing table

             

            Sub CreateTable

             

            Set tb= ActiveDocument.GetSheetObject("TB01")

            tb.AddField "FieldName1"

            tb.AddField "FieldName2"

             

            End Sub

             

             

             

             

            regards

            Kamal