will1128
08-31-2010, 03:12 PM
I've created a button to draw a table. How do I make sure the contents inside the table fit to the table? Combo boxes are causing the problem.
Here's my code:
Public Sub AddScheduleButton_Click()
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.Tables.Add Range:=myRange, NumRows:=3, NumColumns:= _
8, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
ActiveDocument.Tables(1).Cell(2, 1).Range.Text = "Start Time"
ActiveDocument.Tables(1).Cell(3, 1).Range.Text = "End Time"
ActiveDocument.Tables(1).Cell(1, 2).Range.Text = "Sunday"
ActiveDocument.Tables(1).Cell(1, 3).Range.Text = "Monday"
ActiveDocument.Tables(1).Cell(1, 4).Range.Text = "Tuesday"
ActiveDocument.Tables(1).Cell(1, 5).Range.Text = "Wednesday"
ActiveDocument.Tables(1).Cell(1, 6).Range.Text = "Thursday"
ActiveDocument.Tables(1).Cell(1, 7).Range.Text = "Friday"
ActiveDocument.Tables(1).Cell(1, 8).Range.Text = "Saturday"
Dim i As Integer
For i = 2 To 8
'populate 1st and 2nd row with combo boxes
ActiveDocument.Tables(1).Cell(2, i).Select
Selection.InlineShapes.AddOLEControl ClassType:="Forms.ComboBox.1"
ActiveDocument.Tables(1).Cell(3, i).Select
Selection.InlineShapes.AddOLEControl ClassType:="Forms.ComboBox.1"
Debug.Print i
Next i
ActiveDocument.Tables(1).AutoFitBehavior wdAutoFitContent
Debug.Print myRange
End Sub
Edited 1-Sep-10 by geekgirlau. Reason: insert vba tags
Here's my code:
Public Sub AddScheduleButton_Click()
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
ActiveDocument.Tables.Add Range:=myRange, NumRows:=3, NumColumns:= _
8, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
ActiveDocument.Tables(1).Cell(2, 1).Range.Text = "Start Time"
ActiveDocument.Tables(1).Cell(3, 1).Range.Text = "End Time"
ActiveDocument.Tables(1).Cell(1, 2).Range.Text = "Sunday"
ActiveDocument.Tables(1).Cell(1, 3).Range.Text = "Monday"
ActiveDocument.Tables(1).Cell(1, 4).Range.Text = "Tuesday"
ActiveDocument.Tables(1).Cell(1, 5).Range.Text = "Wednesday"
ActiveDocument.Tables(1).Cell(1, 6).Range.Text = "Thursday"
ActiveDocument.Tables(1).Cell(1, 7).Range.Text = "Friday"
ActiveDocument.Tables(1).Cell(1, 8).Range.Text = "Saturday"
Dim i As Integer
For i = 2 To 8
'populate 1st and 2nd row with combo boxes
ActiveDocument.Tables(1).Cell(2, i).Select
Selection.InlineShapes.AddOLEControl ClassType:="Forms.ComboBox.1"
ActiveDocument.Tables(1).Cell(3, i).Select
Selection.InlineShapes.AddOLEControl ClassType:="Forms.ComboBox.1"
Debug.Print i
Next i
ActiveDocument.Tables(1).AutoFitBehavior wdAutoFitContent
Debug.Print myRange
End Sub
Edited 1-Sep-10 by geekgirlau. Reason: insert vba tags