Macro to find and replace paragraph markers with tabs

I

Ian Richardson

Hi

I'm trying to convert several tables in Word 2003 to standard tabbed text so
I can import it into Excel.

I've recorded a macro that converts the table to text seperated by tabs but
then I need to replace the remainder paragraphs with tabs. Recording the
macro goes OK.

The table gets converted and the text is still selected so Find, Replace ^p
with ^t and I get asked to check all the doc after it's replaced the
selection, I say No and close the dialog box. When I run the macro it
converts ALL paras to tabs and not just the selection. This is the macro I've
recorded. Am I missing something??

Many thanks

Ian

Sub Macrotable()
'
'
' Macro recorded 01/06/2009 by me
'
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.ConvertToTable Separator:=wdSeparateByDefaultListSeparator, _
NumColumns:=3, NumRows:=1, AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.Tables(1).Select
Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:= _
True
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = "^t"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Selection.Find.Execute Replace:=wdReplaceAll
End With
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub
 
D

DerbyDad03

Hi

I'm trying to convert several tables in Word 2003 to standard tabbed text so
I can import it into Excel.

I've recorded a macro that converts the table to text seperated by tabs but
then I need to replace the remainder paragraphs with tabs. Recording the
macro goes OK.

The table gets converted and the text is still selected so Find, Replace ^p
with ^t and I get asked to check all the doc after it's replaced the
selection, I say No and close the dialog box. When I run the macro it
converts ALL paras to tabs and not just the selection. This is the macro I've
recorded. Am I missing something??

Many thanks

Ian
--- Code snipped ---

I'm not sure I see your issue, so let me tell you what I did.

I start with a doc that looks like this, other than the Begin and End
lines

- Begin Doc Example -

This is Line 1

This is Line 2

*** 5 column x 4 row table goes here ***

This is Line 3

This is Line 4

- End Doc Example -

I selected the table and ran your code.

I end up with this:

This is Line 1

This is Line 2

*** All the text in the table is now a single line separated by tabs
with a single paragraph mark at the end.

This is Line 3

This is Line 4


Is this not what you are getting?
 

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