Hi
I have large documents with different styles for words/paragraphs/etc within or outside of the tables.
I have written a macro which searching for a particular style and replaces that with a tag. For tables, it seems to do this on a per cell basis. This makes the process so slow. Foer example, I had the macro running overnight replacing styles with tags and it is still going18 hours later. :(.
So, is there any way of sort of 'looking ahead' in a table to see if 'all' the words are for a specific style? This would mean that we could select the whole table and reset it to a tag.
Thanks.
Robie
tagging a specific styled words
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: tagging a specific styled words
Will the target style always be applied to entire cells? Or could it be applied to part of a cell?
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: tagging a specific styled words
That's the problem. It could be applied to part of the cell but for 90% of the cells it is applied to the whole cell.HansV wrote:Will the target style always be applied to entire cells? Or could it be applied to part of a cell?
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: tagging a specific styled words
I'll see if I can come up with something, but it might not be easy.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: tagging a specific styled words
Thanks Hans but don't worry too much.HansV wrote:I'll see if I can come up with something, but it might not be easy.
If I have to I will do some of it by hand :(
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: tagging a specific styled words
The problem is that the end-of-row marker in a table is not formatted with the style of the surrounding text. I wrote a macro, but it was extremely slow - it took a minute or more to run on a one-page document, and it turned out to be unreliable too. So I'm afraid I have no solution for you.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: tagging a specific styled words
No problem Hans, at least you tried.HansV wrote:The problem is that the end-of-row marker in a table is not formatted with the style of the surrounding text. I wrote a macro, but it was extremely slow - it took a minute or more to run on a one-page document, and it turned out to be unreliable too. So I'm afraid I have no solution for you.
Thanks anyway. I will just have to do it by hand
-
- Microsoft MVP
- Posts: 1320
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: tagging a specific styled words
It should be possible to do this with a Replace All operation instead of a loop. Because it's all machine code, it will be much faster than a VBA loop.
In the user interface, put the cursor in the Find What box of the Replace dialog. Click the More button, then click the Format button, click Style in the menu, and select the style you want to replace. Then click in the Replace With box, type the code ^& (which represents the found text) surrounded by the tag, and click Format > Style and choose either Normal (if the style being replaced is a paragraph style or a linked style) or Default Paragraph Font (if you're replacing a character style). Finally, click the Replace All button.
If you're writing a macro for some other purpose or to process multiple styles, and want to include this, we can guide you to code a similar procedure.
In the user interface, put the cursor in the Find What box of the Replace dialog. Click the More button, then click the Format button, click Style in the menu, and select the style you want to replace. Then click in the Replace With box, type the code ^& (which represents the found text) surrounded by the tag, and click Format > Style and choose either Normal (if the style being replaced is a paragraph style or a linked style) or Default Paragraph Font (if you're replacing a character style). Finally, click the Replace All button.
If you're writing a macro for some other purpose or to process multiple styles, and want to include this, we can guide you to code a similar procedure.
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: tagging a specific styled words
That's indeed easy, Jay:
But such a macro will surround the text in individual cells with tags, and my impression was that Robie doesn't want that.
Code: Select all
Sub Test()
Call TagStyle("MyStyle")
End Sub
Sub TagStyle(StyleName As String)
Application.ScreenUpdating = False
With ActiveDocument.Content.Find
.Text = ""
.ClearFormatting
.Format = True
.Style = ActiveDocument.Styles(StyleName)
.Replacement.Text = "<tag>^&</tag>"
.Replacement.ClearFormatting
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans