Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default suddenly experiencing error messages with table macro

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

  #2   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default suddenly experiencing error messages with table macro

I discovered what was wrong. Some of my tables have two different kinds
of styles in cell(1,1). That's why the macro was working before, but
then suddenly threw error messages at me -- because previously, all my
tables had only one style.

How do I modify the following macro so that I can allow more than one
style in Cell(1,1)? In other words, how can I write an Or statement in
there -- like If (1,1) has Table Header style or Image style or Figure
Caption style, then ....

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

  #3   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default suddenly experiencing error messages with table macro

I found a site that provides some instruction on including Or
statements, but modification of the following code doesn't seem to
work:


Sub ConvertRefTables()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
If oTbl.Cell(1, 1).Range.Style = ActiveDocument.Styles("Table
Header") _
Or oTbl.Cell(1, 1).Range.Style =
ActiveDocument.Styles("Caption-figure") _
Then
With oTbl
.Style = ActiveDocument.Styles("Reftable")
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 75
End With
End If
Next oTbl
End Sub

Can someone point out what I'm doing wrong?

  #4   Report Post  
Posted to microsoft.public.word.tables
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default suddenly experiencing error messages with table macro

hi Tom,

Try:

Sub ConvertRefTables()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
If oTbl.Cell(1, 1).Range.Paragraphs(1).Style = _
ActiveDocument.Styles("Table Header") Then
With oTbl
.Range.Paragraphs(1).Style = ActiveDocument.Styles("Reftable")
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 75
End With
End If
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
|


  #5   Report Post  
Posted to microsoft.public.word.tables
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default 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
|




  #6   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default suddenly experiencing error messages with table macro

Thanks for your help with this. I tried that code and it seems to work,
but then my code breaks elsewhere (not sure why). I'll have to
investigate a little more. Thanks again.

  #7   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default suddenly experiencing error messages with table macro

I can't quite get it to work. I have two table macros working, and one
of them always gets stuck on the following line:

..Range.Paragraphs(1).Style = ActiveDocument.Styles("Reftable Flush")

I've triple checked to make sure what I have a Reftable Flush style. It
is a table style, but I didn't think that mattered. Is there anything
else I can try?

Here are the two macros:

Sub ConvertRefTables2()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
If oTbl.Cell(1, 1).Range.Paragraphs(1).Style = _
ActiveDocument.Styles("Table Header") Then
With oTbl
.Range.Paragraphs(1).Style =
ActiveDocument.Styles("Reftable")
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 75
End With
End If
Next oTbl
End Sub

Sub ConvertRefTablesFlush2()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
If oTbl.Cell(1, 1).Range.Paragraphs(1).Style = _
ActiveDocument.Styles("Table Header Flush") Then
With oTbl
.Range.Paragraphs(1).Style =
ActiveDocument.Styles("Reftable Flush")
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 83
End With
End If
Next oTbl
End Sub

I don't know why, but every time I

  #8   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default suddenly experiencing error messages with table macro

Macropod,

You were kind enough to help me with the code, but it just didn't work
for me. I think if I switch what I'm trying to do a little, I can get
around the problem.

What if I could change my IF statement so that instead of saying, "If
in cell(1,1) it has the Table Header style, THEN do this...

To the following:

IF in cell(1,1) the first word is "Note," THEN do this....

How would I apply that new IF statement to the original macro?

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

Thanks in advance for your help.

Tom

  #9   Report Post  
Posted to microsoft.public.word.tables
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default suddenly experiencing error messages with table macro

Hi Tom,

There's no logical reason why the macro would work with one set of styles and
not another - unless the errant one refers to a non-existent style. Are you
sure it's "Reftable Flush" and not "ReftableFlush", for example?

As an aside, you could combine the two macros into one, with an 'ElseIf for
the second style.

Cheers

--
macropod
[MVP - Microsoft Word]


"Tom" wrote in message
oups.com...
| I can't quite get it to work. I have two table macros working, and one
| of them always gets stuck on the following line:
|
| .Range.Paragraphs(1).Style = ActiveDocument.Styles("Reftable Flush")
|
| I've triple checked to make sure what I have a Reftable Flush style. It
| is a table style, but I didn't think that mattered. Is there anything
| else I can try?
|
| Here are the two macros:
|
| Sub ConvertRefTables2()
| Dim oTbl As Table
| For Each oTbl In ActiveDocument.Tables
| If oTbl.Cell(1, 1).Range.Paragraphs(1).Style = _
| ActiveDocument.Styles("Table Header") Then
| With oTbl
| .Range.Paragraphs(1).Style =
| ActiveDocument.Styles("Reftable")
| .PreferredWidthType = wdPreferredWidthPercent
| .PreferredWidth = 75
| End With
| End If
| Next oTbl
| End Sub
|
| Sub ConvertRefTablesFlush2()
| Dim oTbl As Table
| For Each oTbl In ActiveDocument.Tables
| If oTbl.Cell(1, 1).Range.Paragraphs(1).Style = _
| ActiveDocument.Styles("Table Header Flush") Then
| With oTbl
| .Range.Paragraphs(1).Style =
| ActiveDocument.Styles("Reftable Flush")
| .PreferredWidthType = wdPreferredWidthPercent
| .PreferredWidth = 83
| End With
| End If
| Next oTbl
| End Sub
|
| I don't know why, but every time I
|


  #10   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default suddenly experiencing error messages with table macro

I tweaked your code a little and it fixed it. I changed Paragraphs(1)
to Characters(1) in this macro and my other table macros and it no
longer gives me an error msg when I run them. Here's the slightly
tweaked code:

Sub ConvertRefTables()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
If oTbl.Cell(1, 1).Range.Characters(1).Style = _
ActiveDocument.Styles("Table Header") Then
With oTbl
.Range.Characters(1).Style =
ActiveDocument.Styles("Reftable")
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 75
End With
End If
Next oTbl
End Sub

The first characters in my table always have the correct style. If the
table ever has any other style applied to it, that style comes in
later. Thanks again for your help Macropod.

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error messages when using table formula after moving column tot's hunguponword Tables 3 November 26th 06 03:27 AM
Losing textbox on table Jack Tables 13 November 21st 06 03:09 AM
Change Table Background Macro Jeff Ditty Tables 1 March 28th 06 04:32 AM
Select specific cells in table via macro Bill Sturdevant Microsoft Word Help 1 July 27th 05 03:01 PM
Word 2003 Table AutoFormat vs Macro vs VBA Kind writer/user/programmer Tables 1 October 28th 04 03:14 PM


All times are GMT +1. The time now is 11:52 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"