Before table

F

Frantisek Horalek

Hello,
I need to place some text just before every table in the document
which (the table) has the first-cell-text like "This example".
Is it possible?
Pushing me forward will be enough, I will complete that script with
your suggestions...

Thank you!
 
J

Jonathan West

Frantisek Horalek said:
Hello,
I need to place some text just before every table in the document
which (the table) has the first-cell-text like "This example".
Is it possible?
Pushing me forward will be enough, I will complete that script with
your suggestions...

Thank you!

Something like this should do

Dim oTable as Table
For each oTable in ActiveDocument.Tables
If Instr(oTable.Cell(1, 1).Range.Text, "This example") > 0 Then
With oTable.Range.Paragraphs.First.Previous.Range
.Characters.Last.InsertParagraphBefore
.InsertBefore "Table Caption"
End With
End If
Next oTable


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi Frantisek,
Pushing me forward will be enough,

If so:

With Selection
.Tables(1).Select
.Collapse
.SplitTable
.InsertBefore "aasdasdskd"
End With

Need help on how to process all tables?

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
F

Frantisek Horalek

Something like this should do

Great, it works!

Now I am looking for reason to "group" this to be able to press Back
button just once to get to the situation BEFORE using macro. Now it is
on many clicks on Back button.
I it possible?
I used that in Corel programming vba, but here this:
==========
ActiveDocument.BeginCommandGroup "StredPravyDolni"
..
..
..
ActiveDocument.EndCommandGroup
==========

do not work.

Thank you!
 
J

Jonathan West

Frantisek Horalek said:
Great, it works!

Now I am looking for reason to "group" this to be able to press Back
button just once to get to the situation BEFORE using macro. Now it is
on many clicks on Back button.
I it possible?

No, that is not possible.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi Frantisek,

as far as I see, Jonathan's example does the following:
It creates a new paragraph immediately before the table,
leaves that paragraph empty, and inserts "table caption"
at the beginning of the paragraph predecing the newly
created paragraph!

Redoing it all would in my example mean,
delete all paragraphs immediately preceding tables,
and is not a big problem, if I get you right.

' ------
Sub test8948()
Dim oTable As Table
Dim rtmp As Range
For Each oTable In ActiveDocument.Tables
Set rtmp = oTable.Range.Cells(1).Range
rtmp.Select
Selection.SplitTable
rtmp.InsertBefore "table heading"
Next oTable
' redo
For Each oTable In ActiveDocument.Tables
oTable.Range.Paragraphs(1).Previous.Range.Delete
Next oTable
End Sub
' ----

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top