Results 1 to 14 of 14

Thread: Cannot access individual columns because table has mixed cell widths

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    I have posted another thread under " 'flexible' table ", although unsolved.
    Attached is my code and I have tested it is possible to change the column width when creating a table.
    Thanks.
    Public objApp As Word.Application 
    Public Tbl1 As Table 
     
    Private Sub Command1_Click() 
        On Error Resume Next 
        Set objApp = GetObject(, "Word.Application") 
        If objApp Is Nothing Then 
            Set objApp = CreateObject("Word.Application") 
        End If 
        With objApp 
            .Documents.Add , , , True 
            .Visible = False 
        End With 
        For intCounter1 = 1 To 3 
            If intCounter1 = 1 Then 
                Set Tbl1 = objApp.ActiveDocument.Tables.Add _ 
                (Range:=Selection.Range, NumRows:=1, NumColumns:=2) 
                Tbl1.Columns(1).Width = 100 
                Tbl1.Columns(2).Width = 100 
            Else 
                Selection.MoveDown Unit:=wdLine, Count:=1 
                Selection.InsertRows 1 
            End If 
            Tbl1.Cell(intCounter1, 1).Range.Text = "Table1 - col1" & intCounter1 
            Tbl1.Cell(intCounter1, 2).Range.Text = "Table1 - col2" 
        Next 
        objApp.ActiveDocument.SaveAs FileName:="c:\test1.doc" 
        objApp.Quit False 
        Set objApp = Nothing 
        MsgBox "done" 
        Set Tbl1 = Nothing 
        objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 _ 
        ' <- move to end of table
        objApp.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove _ 
        ' <- move foward 1 line
    End Sub
    Last edited by Aussiebear; 03-21-2025 at 06:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •