suddenly experiencing error messages with table macro
Hi Tom,
If your cell might have more than one paragraph formatted in the 'Table
Header' style, or that paragraph isn't necessarily the first, try:
Sub ConvertRefTables()
Dim oTbl As Table
Dim oPara As Paragraph
For Each oTbl In ActiveDocument.Tables
For Each oPara In oTbl.Cell(1, 1).Range.Paragraphs
If oPara.Style = ActiveDocument.Styles("Table Header") Then
oPara.Style = ActiveDocument.Styles("Reftable")
With oTbl
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 75
End With
End If
Next oPara
Next oTbl
End Sub
Cheers
--
macropod
[MVP - Microsoft Word]
"Tom" wrote in message
ups.com...
| My document was running the following macro without any problems:
|
| Sub ConvertRefTables()
|
| Dim oTbl As Table
| For Each oTbl In ActiveDocument.Tables
| If oTbl.Cell(1, 1).Range.Style = _
| ActiveDocument.Styles("Table Header") Then
| With oTbl
|
| .Style = ActiveDocument.Styles("Reftable")
| .PreferredWidthType = wdPreferredWidthPercent
| .PreferredWidth = 75
|
| End With
| End If
| Next oTbl
| End Sub
|
| However, when I run it now, I receive an error message that says
| "Object variable or with block variable not set." And it highlights
| this part of the macro code:
|
| If oTbl.Cell(1, 1).Range.Style = _
| ActiveDocument.Styles("Table Header") Then
|
| My document does have a table with the Table Header style is cell
| (1,1), so I'm not sure why I'm getting the error.
|
| I am running the macro with other macros in the document -- maybe
| that's the problem? I copied the macro into a new document and it
| worked fine. It's just when I include it with the other macros that it
| starts to give me with error message. Can anyone help me?
|
| Thanks,
|
| Tom
|
|