paddysheeran
10-22-2010, 03:37 AM
Hi All,
Im experiecing an error message when trying to run the following.
The code used to transfer the data from excel to word is:
Public t as Word.Range
Public Rng as Range
Sub WS_Weekly_Tickets()
Set wsSource = ActiveWorkbook.Sheets("Customer_Incidents_WordReport")
Set t = wdDoc.Bookmarks("Incidents_Weekly").Range
wsSource.Activate
Range("A1").CurrentRegion.Select
Set Rng = Selection
Rng.Resize(Selection.Rows.Count, Selection.Columns.Count - 1).Select
Set Rng = Selection
Rng.Copy
t.PasteAndFormat (wdPasteDefault)
Weekly_Tickets_Style
End Sub
The above works fine and pastes the data into the bookmark without an issue. When Weekly_Tickets_Style is called there in lies the problem. The following codes applies the style and font size but when the first line of the Column width adjustment is reached the error message appears:
"Run-time error '4608':
Value out of range
Sub Weekly_Tickets_Style()
With t
.Style = "Weekly_Tickets"
.Font.Size = "8"
.Tables(1).Columns(1).SetWidth ColumnWidth:=5, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(2).SetWidth ColumnWidth:=5, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(3).SetWidth ColumnWidth:=6, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(4).SetWidth ColumnWidth:=8, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(5).SetWidth ColumnWidth:=10, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(6).SetWidth ColumnWidth:=6, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(7).SetWidth ColumnWidth:=9, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(8).SetWidth ColumnWidth:=10, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(9).SetWidth ColumnWidth:=2, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(10).SetWidth ColumnWidth:=5, RulerStyle:= _
wdAdjustNone
End With
End Sub
Any help would be greatly appreciated.
thanks,
Paddy.
Im experiecing an error message when trying to run the following.
The code used to transfer the data from excel to word is:
Public t as Word.Range
Public Rng as Range
Sub WS_Weekly_Tickets()
Set wsSource = ActiveWorkbook.Sheets("Customer_Incidents_WordReport")
Set t = wdDoc.Bookmarks("Incidents_Weekly").Range
wsSource.Activate
Range("A1").CurrentRegion.Select
Set Rng = Selection
Rng.Resize(Selection.Rows.Count, Selection.Columns.Count - 1).Select
Set Rng = Selection
Rng.Copy
t.PasteAndFormat (wdPasteDefault)
Weekly_Tickets_Style
End Sub
The above works fine and pastes the data into the bookmark without an issue. When Weekly_Tickets_Style is called there in lies the problem. The following codes applies the style and font size but when the first line of the Column width adjustment is reached the error message appears:
"Run-time error '4608':
Value out of range
Sub Weekly_Tickets_Style()
With t
.Style = "Weekly_Tickets"
.Font.Size = "8"
.Tables(1).Columns(1).SetWidth ColumnWidth:=5, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(2).SetWidth ColumnWidth:=5, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(3).SetWidth ColumnWidth:=6, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(4).SetWidth ColumnWidth:=8, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(5).SetWidth ColumnWidth:=10, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(6).SetWidth ColumnWidth:=6, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(7).SetWidth ColumnWidth:=9, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(8).SetWidth ColumnWidth:=10, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(9).SetWidth ColumnWidth:=2, RulerStyle:= _
wdAdjustNone
.Tables(1).Columns(10).SetWidth ColumnWidth:=5, RulerStyle:= _
wdAdjustNone
End With
End Sub
Any help would be greatly appreciated.
thanks,
Paddy.