Hi and thanks for replying again.
The code segment works fine on my one workstation. It fails on my other workstation and, on debug, highlights the first CentimetersToPoints(4.5) statement immediately after With oTable.
I do have the End With statement; right at the end of that code segment?
I feel it might have been a time issue because if I use F8 during debug mode then the code executes fine. In fact if I tell the code to continue running it keeps reporting an error on the first line after a new table has been created but then continues to run without issue once I instruct it to continue.
The macro is not run again, it is a lengthy but simple sequential operation and all tables are separated. As I say, it works perfectly on my one workstation and stutteringly on my other one.
The whole subroutine code is here...
Private Sub cmd_next2_Click() ' Next button (2)
Dim i As Integer, k As Integer
Dim s_aims As String
k = 0
ReDim aims(lst_aims.ListCount - 1)
For i = 0 To lst_aims.ListCount - 1
If lst_aims.Selected(i) = True Then
aims(k) = lst_aims.List(i, 0)
k = k + 1
If s_aims = "" Then
s_aims = (i + 1) & ". " & lst_aims.List(i, 3)
Else
s_aims = s_aims & vbCrLf & (i + 1) & ". " & lst_aims.List(i, 3)
End If
End If
Next i
ActiveDocument.Paragraphs.Add
Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseEnd
' Create and populate the first table on the form
ActiveDocument.Tables.Add Range:=myRange, numRows:=2, numColumns:=2
With ActiveDocument.Tables(1)
.Columns(1).PreferredWidth = CentimetersToPoints(4.5)
.Columns(1).Shading.BackgroundPatternColor = RGB(192, 192, 192)
.Columns(1).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(1).Range.Bold = True
.Columns(1).Cells(1).Range.Text = "Assignment Title:"
.Columns(1).Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(2).Range.Bold = True
.Columns(1).Cells(2).Range.Text = "Assessor:"
.Columns(2).PreferredWidth = CentimetersToPoints(11.5)
.Columns(2).Cells(1).Range.Text = txt_number.value & ": " & txt_title.value
.Columns(2).Cells(2).Range.Text = cmb_assessor.value
.Borders.InsideLineStyle = wdLineStyleSingle
.Borders.OutsideLineStyle = wdLineStyleSingle
End With
' Create and populate the second table on the form - minus specific data (labels only)
ActiveDocument.Paragraphs.Add
Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseEnd
ActiveDocument.Tables.Add Range:=myRange, numRows:=3, numColumns:=2
With ActiveDocument.Tables(2)
.Columns(1).PreferredWidth = CentimetersToPoints(4.5)
.Columns(1).Shading.BackgroundPatternColor = RGB(192, 192, 192)
.Columns(1).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(1).Range.Bold = True
.Columns(1).Cells(1).Range.Text = "Date Issued:"
.Columns(1).Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(2).Range.Bold = True
.Columns(1).Cells(2).Range.Text = "Hand In Date:"
.Columns(1).Cells(3).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(3).Range.Bold = True
.Columns(1).Cells(3).Range.Text = "Duration (Approx.):"
.Columns(2).PreferredWidth = CentimetersToPoints(11.5)
.Columns(2).Cells(2).Split 1, 3
.Rows(2).Cells(3).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Rows(2).Cells(3).Shading.BackgroundPatternColor = RGB(192, 192, 192)
.Rows(2).Cells(3).Range.Bold = True
.Rows(2).Cells(3).Range.Text = "Assessment Date:"
.Borders.InsideLineStyle = wdLineStyleSingle
.Borders.OutsideLineStyle = wdLineStyleSingle
End With
' Create and populate the third table on the form
ActiveDocument.Paragraphs.Add
Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseEnd
ActiveDocument.Tables.Add Range:=myRange, numRows:=3, numColumns:=2
With ActiveDocument.Tables(3)
.Columns(1).PreferredWidth = CentimetersToPoints(4.5)
.Columns(1).Shading.BackgroundPatternColor = RGB(192, 192, 192)
.Columns(1).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(1).Range.Bold = True
.Columns(1).Cells(1).Range.Text = "Qualification Covered:"
.Columns(1).Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(2).Range.Bold = True
.Columns(1).Cells(2).Range.Text = "Units Covered:"
.Columns(1).Cells(3).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Cells(3).Range.Bold = True
.Columns(1).Cells(3).Range.Text = "Learning Aims Covered:"
.Columns(2).PreferredWidth = CentimetersToPoints(11.5)
.Columns(2).Cells(1).Range.Text = myCourse.title
.Columns(2).Cells(2).Range.Text = lst_unit.List(lst_unit.ListIndex, 1)
.Columns(2).Cells(3).Range.Text = s_aims
.Borders.InsideLineStyle = wdLineStyleSingle
.Borders.OutsideLineStyle = wdLineStyleSingle
End With
Me.tabs_info.Pages(2).Visible = True
Me.tabs_info.Pages(1).Visible = False
If edit_data = True Then
set_dates issue_date, handin_date, assessment_date
Else
set_dates Date, DateAdd("d", 14, Date), DateAdd("d", 14, d_handin.value)
End If
End Sub
Oooo, can you name the tables? Never found that one; that'd be nicer (and easier) to work with.