Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert block of text using VBA 1

Status
Not open for further replies.

SUSANVV

MIS
Feb 13, 2001
247
US
We have an online form with bookmarks that are filled in on opening depending upon a selection from a dialog box that opens as the document opens.

I would like to insert, as one unit multiple lines of text. Everything on the form is the same until the end of the form. The last section (paragraph)needs to be entirely different depending upon the choices on the opening dialog box. Inserting individual lines of text is no problem and this could be done with 6 different bookmarks, one for each line but there must be a better way.

TIA for any help.
Sue
 
I am sure there si a better way.

Coould you give more detail?
The last section (paragraph)needs to be entirely different depending upon the choices on the opening dialog box.
This sounds like ONE paragraph.
Inserting individual lines of text is no problem and this could be done with 6 different bookmarks, one for each line but there must be a better way.
This sounds like multiple paragraphs.

So.

Are these paragraphs coming from different sources?
Why would you use 6 different bookmarks?
Could this not be just one chunk of text inserted at the end of the document?
Why use a bookmark at all? Just go to the end of the document and put in the text.

Inserting multiple "lines" of text is not a problem. If by "lines" you mean paragraphs, then you put in paragraph marks.
Code:
Dim sInsertText As String
sInsertText = "This is the first paragraph (line)." & _
   vbCrLf & "This is the second paragraph (line)." & _
   vbCrLf & "This is the third paragraph (line)."
ActiveDocument.Range.InsertAfter sInsertText
would put

This is the first paragraph (line).
This is the second paragraph (line).
This is the third paragraph (line).

at the end of the document.

If this is not what you are thinking about, you will need to describe your situation more.


Gerry
My paintings and sculpture
 
Hi,
Thanks for the reply. Your code looks like the trick. Yes it could be just one chunk of text-that is what I was hoping for. It is a form letter where everything in the letter is the same until the last several lines. They are a statement of verification for something legal. For one county the verification statement is different than for another county. It seemed sensless to have 2 different documents for about 6 lines of text. All of the lines for one county are numbered. For the 2nd county, 2 of the lines are numbered and the rest is a 2-line statement.

I have one other glitch to work around. For one of the county's I had a variable inserted into the middle of a sentence depending upon something chosen in the opening dialog box. I will have to insert an If-Then at the proper place in the code to insert one entire sentence with the specific choice of variable for each Else.

Thanks for your help. If you have any other ideas I would appreciate it.

Thanks

Sue
 
Hmmm.

RE: different text for different countries.

Make different AutoText for each. For example, I just made an AutoText entry composed of three paragraphs, like this:

This is country A
1. And its text
2. Which is numbered

I named the AutoText "CountryA". Now I can run:
Code:
Selection.EndKey Unit:=wdStory
ActiveDocument.AttachedTemplate.AutoTextEntries("CountryA").Insert _
        Where:=Selection.Range, RichText:=True
which goes to the end of the document and inserts the AutoText.

So say your userform sets a variable - strCountry - heck you could just use a letter, but it may be better to use a name. And say, you have AutoText entries:

USA
France
Chile
Japan

each different.

Set a string variable strCountry - use an textbox to get it from the user, or a combobox with the countries listed.

After everything else is done:
Code:
Selection.EndKey Unit:=wdStory
ActiveDocument.AttachedTemplate.AutoTextEntries(Country)Insert _
        Where:=Selection.Range, RichText:=True


Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top