none
VSTO - Need to insert a Word TextBox into a Word 2010 table cell and a colored shape into another cell RRS feed

  • Question

  • I've got the table created and can put text in particular cells; now, I need to place a text box (rotated 270 degrees) into an empty cell (filling the cell) and a colored shape in another empty cell (again, filling the cell)... My pathetic attempts in a test project is below:

      

    Thanks

      'This routine creates the labels to put on the music
        ' It will have the library number on the left and the 
        '     piece number (or Director) on the right.
        Public Sub Create8161()
            Dim oWord As Word.Application
            Dim oDoc As Word.Document
            Dim oTable As Word.Table
            Dim oTable11 As Word.Table
            Dim oTable12 As Word.Table
            Dim tRow As Integer
            Dim tCol As Integer
            Dim otRange11 As Word.Range
            Dim otRange12 As Word.Range
            Dim otRange11TB As Word.Range
            Dim otRange12TB As Word.Range
            Dim otRange11Colors As Word.Range
            Dim otRange12Colors As Word.Range
            Dim otShapeTB11 As Word.Shape
            Dim otShapeTB12 As Word.Shape

            'Start Word and open the document template.
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Add

            tRow = 10
            tCol = 7
            'Place a table in the document
            oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, tRow, tCol)
            'Set Paragraph / Font / Alignment attributes
            With oTable.Range
                .ParagraphFormat.SpaceBefore = 0
                .ParagraphFormat.SpaceAfter = 0
                .Font.Bold = True
                '.Font.Size = 14
                .Font.Name = "Arial"
                '"""""""""""""""""""""""""" Debug""""""""""""""""""""
                .Cells.Borders.Enable = True
                '""""""""""""""""""""""""""""""""""""""""""""""""""""
            End With
            'Set the margins for the page
            With oDoc.PageSetup
                .LeftMargin = oWord.InchesToPoints(0.3)
                .RightMargin = oWord.InchesToPoints(0.25)
                .TopMargin = oWord.InchesToPoints(0.25)
                .BottomMargin = oWord.InchesToPoints(0.25)
            End With
            'Setup the master table
            For r = 1 To tRow
                For c = 1 To tCol Step 2
                    oTable.Cell(r, c).VerticalAlignment = _
                      Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter
                Next c
            Next r
            'Set the column widths
            With oTable.Columns
                .Item(1).Width = oWord.InchesToPoints(3.0)
                .Item(2).Width = oWord.InchesToPoints(0.5)
                .Item(3).Width = oWord.InchesToPoints(0.5)
                .Item(4).Width = oWord.InchesToPoints(0.2)
                .Item(5).Width = oWord.InchesToPoints(3.0)
                .Item(6).Width = oWord.InchesToPoints(0.5)
                .Item(7).Width = oWord.InchesToPoints(0.5)
            End With
            'Set the row heights
            For i = 1 To tRow
                oTable.Rows.Item(i).Height = oWord.InchesToPoints(1.0)
                oTable.Rows.Item(i).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
            Next i

            otRange11 = oTable.Cell(1, 1).Range
            otRange11TB = oTable.Cell(1, 2).Range
            otRange11Colors = oTable.Cell(1, 3).Range
            otRange12 = oTable.Cell(1, 5).Range
            otRange12TB = oTable.Cell(1, 6).Range
            otRange12Colors = oTable.Cell(1, 7).Range


            oTable11 = oWord.ActiveDocument.Tables.Add(Range:=otRange11, _
              NumRows:=4, NumColumns:=1)
            oTable11.Rows.Add()
            oTable11.Rows.Add()
            oTable11.Rows.Add()

            oTable12 = oWord.ActiveDocument.Tables.Add(Range:=otRange12, _
              NumRows:=4, NumColumns:=1)
            oTable12.Rows.Add()
            oTable12.Rows.Add()
            oTable12.Rows.Add()

            oTable11.PreferredWidth = oWord.InchesToPoints(2.85)
            oTable11.Rows(1).Height = oWord.InchesToPoints(0.2)
            oTable11.Rows(2).Height = oWord.InchesToPoints(0.3)
            oTable11.Rows(3).Height = oWord.InchesToPoints(0.28)
            oTable11.Rows(4).Height = oWord.InchesToPoints(0.2)

            oTable12.PreferredWidth = oWord.InchesToPoints(2.85)
            oTable12.Rows(1).Height = oWord.InchesToPoints(0.2)
            oTable12.Rows(2).Height = oWord.InchesToPoints(0.3)
            oTable12.Rows(3).Height = oWord.InchesToPoints(0.28)
            oTable12.Rows(4).Height = oWord.InchesToPoints(0.2)

            oTable11.Rows(1).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
            oTable11.Rows(2).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
            oTable11.Rows(3).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
            oTable11.Rows(4).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly

            oTable12.Rows(1).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
            oTable12.Rows(2).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
            oTable12.Rows(3).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
            oTable12.Rows(4).HeightRule = Word.WdRowHeightRule.wdRowHeightExactly

            oTable11.Borders.Enable = True
            oTable11.Cell(1, 1).Range.Font.Size = 12
            oTable11.Cell(2, 1).Range.Font.Size = 16
            oTable11.Cell(3, 1).Range.Font.Size = 14
            oTable11.Cell(4, 1).Range.Font.Size = 11
            oTable11.Cell(1, 1).Range.Text = "Row #1"
            oTable11.Cell(2, 1).Range.Text = "Row #2"
            oTable11.Cell(3, 1).Range.Text = "Row #3"
            oTable11.Cell(4, 1).Range.Text = "Row #4"

            oTable12.Borders.Enable = True
            oTable12.Cell(1, 1).Range.Font.Size = 12
            oTable12.Cell(2, 1).Range.Font.Size = 16
            oTable12.Cell(3, 1).Range.Font.Size = 14
            oTable12.Cell(4, 1).Range.Font.Size = 11
            oTable12.Cell(1, 1).Range.Text = "Row #1"
            oTable12.Cell(2, 1).Range.Text = "Row #2"
            oTable12.Cell(3, 1).Range.Text = "Row #3"
            oTable12.Cell(4, 1).Range.Text = "Row #4"

            'otShapeTB11 = oTable.Cell(1, 2).Range.ShapeRange.TextFrame()
            'otShapeTB11 = oWord.ActiveDocument.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationDownward, oTable11.Cell(1, 2), 0, oWord.InchesToPoints(0.5), oWord.InchesToPoints(1.0))

            'otShape11 = oWord..Shapes.AddTextbox _
            ' (Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationDownward, _
            '  1, 1, oWord.InchesToPoints(0.5), oWord.InchesToPoints(1), otRange11TB)
            'otShape11.TextEffect=Word.

            '' ''otShape11 = oWord.ActiveDocument.Shapes.AddTextbox _
            '' ''   (Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationDownward, _
            '' ''    1, 1, oWord.InchesToPoints(0.5), oWord.InchesToPoints(1.0))
            '' '' ''otShape11.TextEffect=Word.

            'oTable.Cell(1, 1).Select()
            'oTable.Cell(1, 1).Range.Tables.Add(oDoc.Bookmarks.Item("\endofdoc"), 4, 1)
            'oTable.Cell(1, 1).Tables.Add(Range:=oTable.Cell(1, 1), NumRows:=4, NumColumns:=1)
            Dim j As Integer
            j = 0
            ''Fill the table

        End Sub 'Create8161

    Wednesday, October 1, 2014 7:19 PM

All replies