store word document in a variable

thierno

New member
Local time
Yesterday, 21:29
Joined
May 1, 2005
Messages
7
hi,

Is there a way to store the text of a word document in a variable without opening the document?

I explain:
I have document1.doc opened
I want to copy and paste the contain of document2.doc at the end of document1.doc without opening document2.doc

I ve tried to use

Open "document2.doc" For Input As #1
Do While Not EOF(3)
Line Input #3, temp
tempstr = tempstr & temp
Loop
Close #3

but I don t get the result

Any idea?
 
Is there a way to store the text of a word document in a variable without opening the document?

No.

Open "document2.doc" For Input As #1

This approach only works for text files (.TXT, .CSV, a couple of less popular others.)

I want to copy and paste the contain of document2.doc at the end of document1.doc without opening document2.doc

No can do. WORD is not a "simple" document format. It contains more crap than a Christmas turkey. Things like Font size, face, and other formatting attributes. Margination. Pagination. Headers and footers. Index entries. Style markers. Virtual tables of contents. The only way to extract the text you want from document 2 is to OPEN document 2. Find the text. Do a text copy and then switch documents, find your insertion point, and do a text paste. (And even THAT statement is a bit glossed over.)

What's the problem with doc2? Got a macro that runs when you open it? Or are you trying to avoid having to account for an updated date of last access?
 
If you want to manipulate a Word document this way then you'll have to use Word's COM objects to do it. The menu bar commands within Word to do this are: Insert / File

What you should do is Record a new macro within Word, select those menu commands and then stop the macro recording. Then, you will have the code base to tweak and accomplish what you're looking to do.
 

Users who are viewing this thread

Back
Top Bottom