creating tabs within text

H

hlngus

How does one create an auto-generated text file with tabs embedded?

I want to emulate a user keying in a tab between lets say the first
word and second word of each line.

The end result is that once pasted, the second word will later be
aligned in the same column position of each line, regardless of the
length of the first word.

I want the following example, with a character that Word can translate
into a tab, with user-entered tabs.

Name: John
Address: Main

What is the character that will generate an ascii 9, that Word can
recognize?
I thought it was the ^t , as in the following snippet:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.Replacement.Text = SPACE
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


Thanks.
 
D

Doug Robbins - Word MVP

Use Edit>Replace to replace

: [spacebar]

with

:^t

Press the spacebar where [spacebar] appears in the above. That will insert
a tab space after the colon and if you have tab stops set up appropriately
in the range of paragraphs, the data will be aligned correctly.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
H

hlngus

Thanks for the helpful response; I should have posted in the
microsoft.public.word.programming .

It was the fact that tab stops weren't set up within the paragraphs
that prevented the tabs from functioning.

Below is the snippet used to allow converting text (in this case <t/
) to tabs:

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<t/>"
.Replacement.Text = vbTab
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Then results were correct once the tab stops were set as below:

ActiveDocument.Paragraphs(2).TabStops.ClearAll
ActiveDocument.Paragraphs(2).TabStops.Add Position:=50,
_
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.Alignment =
wdAlignParagraphLeft

Thanks for the assistance.
 

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