How can I pull a large Word doc into variables in VB6?

I need to read a Word doc, replace some of the information (they are placeholders) and then write the file out to another filename.  The file is over 800k

I've done this many times with HTML files and smaller RTF files . . .but never any so large.  I just open the file in binary mode and read the entire file into a string variable.  I'm pretty sure this won't work with such a large file (am I missing something easy?)

I could really use some direction!  This project is due by Monday and this is my last hurdle!

Thanks!!!!

lthamesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
Have you considered using the OLE Automation to drive the Word application? That way you can use the methods of the Word Object model to change the data at bookmarks or found text.

The snippet demonstrates the code if your placeholders have been implemented as bookmarks. It was written using early binding, but I have commented out the Word object types in the Dims and the Word-defined constant to make it a bit easier to try.
Sub AddTextToBookmark()
    Dim wdApp 'As Word.Application
    Dim wdDoc 'As Word.Document
    Dim bmk 'As Word.Bookmark
    Dim rng 'As Word.Range
    
    Set wdApp = CreateObject("Word.Application")
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Open("C:\MyFolder\MyFile.rtf")
    Set bmk = wdDoc.Bookmarks("MyBookmark")
    Set rng = bmk.Range
    rng.Text = "New Text"
    wdDoc.Bookmarks.Add "MyBookmark", rng 'ensure bookmark contains the new text
    wdDoc.Close -1 'wdSaveChanges
    wdApp.Quit
End Sub

Open in new window

0
lthamesAuthor Commented:
No, I hadn't thought of that.  I will try it.

The placeholders look like this:   [client], [type_text], and [options], etc.  But some of these get replaced with entire paragraphs of formatted text.  Would this be a problem?

Thanks!
0
GrahamSkanRetiredCommented:
That code won't work. It's only for bookmarks. You would best be using Find to locate the position.

In what way is the incoming text formatted? Simply font - name, colour, size etc,  or is there layout - indenting,  spacing, etc to consider.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

lthamesAuthor Commented:
Could I 'bookmark' the placeholders in WORD and then use that code?  IE . . . . bookmark [client] as a bookmard and then replace it?  Or would the Find still be better?

Font, Lists, Indenting . . . but they already have the WORD formatting appled to them; done.  The function as it is now works (opening binary file and replacing the placeholders with the code generated data).  BUT it only works in small pieces, not this entire file!

Thanks for your help!
0
lthamesAuthor Commented:
OH, and does each client machine need WORD installed for this to work?
0
GrahamSkanRetiredCommented:
I don't know your full scenario. If you want to set up a system to do this many times in the future then bookmarks instead of/or as well as text placeholders would be a good idea.

If you have document(s) already with the placeholders then you would need to find them to replace them with bookmarks, so it wouldn't be a lot easier.

You would need to have Word installed to use the Word object library, yes.
0
lthamesAuthor Commented:
Absolutely amazing!!!!!!   I turned pages of code into about 1/2 a page using the Word Object and Find/Replace!  Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.