View Full Version : Macro to paste text into word 2003 doc?
simpleonline
01-28-2011, 12:38 PM
I need to know if it's possible to create a macro that can enter information automatically that I have already create before hand?
How would one do this ?
Thanks
fumei
01-28-2011, 12:46 PM
Yes.
But...
How would one do...WHAT?
You created it in a text file, and you want to get all of it from that textfile?
You created it in a text file, and you want to get SOME of it from that text file?
You created it in a userform, and stored it in a document variable, and you want to get it from there?
You just created it?
You created it before?
You created it in the same document?
You created it in a formfield?
You created it in an Excel file, and want to bring it in from there?
and so on.
simpleonline
01-28-2011, 01:24 PM
howdy...Gerri...I'm here to flustrate you once again....lol...well I have a text file that contains a paragraph of two information that I would like to insert automatically into a letter that I generate.....well there are several different txt files that I would use depending on which one I need but I would create a macro for each one.......I want to know how I could insert the information in that text into a word doc using a macro?
Ex:
The brown cow jumped [would need to insert text file paragrah here] over the red fox
Thanks
fumei
01-28-2011, 01:45 PM
No need for a macro. Use an INCLUDETEXT field. The text would need to be bookmarked though. So the file would have to be, therefore, a Word document.
So, say you have yaddaBlah.doc. You bookmark a paragraph:
"now is the time for whatever blah blah."
You name the bookmark FromThere.
Insert a INCLUDETEXT fiield;
{ INCLUDETEXT "c:\\SomeFolder\\Other\\FooBar.doc" From There }
The text in the bookmark will be in the document.
If it is the whole file you want, you can keep it as a text file, and use INCLUDETEXT with no bookmark.
{ INCLUDETEXT "c:\\SomeFolder\\Other\\FooBar.txt" }
Or, alternatively, you could make an INI file of paragraphs and grab it from there.
C:\zzz\Whatever\Test.ini has:
[MyParagraphs]
1 = “the text of one”
2 = “the text of the second”
3 = “the text of the third”
Now:
System.PrivateProfileString("c:\zzz\Whatever\Test.ini", _
"MyParagraphs", 2)
returns “the text of the second”. This is a string, and can used like any other string, and placed anywhere you CAN place a string. Using the Selection,
Selection.TypeText System.PrivateProfileString("c:\zzz\Whatever\Test.ini", _
"MyParagraphs", 2)which would type "the text of the second" at the Selection point.
inserted or a bookmark, or a ....
Or, alternatively, you could make your inserts as AutoText.
You have lots of options.
gmaxey
01-28-2011, 01:49 PM
Selection.InsertFile "C:\Cow's long and winding jump file.txt", , False, False
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.