Solved

Using VB to add data to MSWord documents

Posted on 2002-06-13
9
187 Views
Last Modified: 2010-05-02
I am attempting to add variable data to several different word documents that reside on a local machine. I wish to use these documents as templates and add data on the fly changing from one template to another as the data file requests. I have written code to select different documents and print data on them but it is painfully slow.

The number of templates I am using will be up to 10. Is there a way to load the documents up and select them as and when required? I also need a fix to append all the documents together as the code I have only sends down 1 sheet at a time not sheets (1 of 3) etc

Thanking you for your forth coming help
Wayne
0
Comment
Question by:wayne_carlisle
9 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7076171
hearing...
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7076445
Well, you can load the different templates into different Word Document Objects, and then switch back and forth between the Word Document objects as the data file requests.

Dim wrdApp As Word.Application
Dim wrdDocTemplate1 As Word.Document
Dim wrdDocTemplate2 As Word.Document


    Set wrdApp = New Word.Application
    Set wrdDocTemplate1 = wrdApp.Documents.Open("C:\Code\Template1.doc")
    Set wrdDocTemplate2 = wrdApp.Documents.Open("C:\Code\Template2.doc")


Then, you can select and write to whichever document you choose, as often as you choose to.

I'm not sure about appending the documents together.  I'd guess that you'd need to create a new document, and perhaps select all of one document and paste it into the new document at a selection point at the end of the document, and continue doing that with each other document, and then print the new document.  

0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7077460
Find something very useful integrates vb with word doc where we can set the variables value in vb then pass to the word doc.

Do a search on freevbcode.com as where i found the code, but unfortunately i forget the exact url.

<listening..>
0
 

Author Comment

by:wayne_carlisle
ID: 7083182
I have tried the above but it appears to be unworkable. On a laser printer it took 12 minutes to print 27 sheets?

I would like to import the data from the word document and somehow put it into the printers object but I'm not sure if this is going to be possible. These templates have bitmap signatures as well!
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 18

Expert Comment

by:mdougan
ID: 7084486
I guess I'm still a little confused about what you are doing.  If you could show any relevent code, that would be helpful.  Also, I'm not sure that it's the code that is slowing you down, I'm curious about your templates, maybe there is something there that is causing the problem... again, if we could see a snippit of code, then we might be able to test against other templates and we could see which area (code or templates) is bogging you down.  Then, we might be better able to help.

You can bring data into VB from Word, and then you can issue Printer.Print statements, but I doubt that you want to do that, as it's a painful process, difficult to format things properly, and will probably be as slow to print as anything that Word would do.
0
 

Author Comment

by:wayne_carlisle
ID: 7093707
I have changed my tact on how I am going to achieve my objective. I have been working on saving word documents as .rtf files and importing the text into RichTextBoxes. Once these files are into these RichTextBoxes I can do what I want quite successfully. However I have another problem that I would be happy to give the points away for.

This is that I now need to create RichTextBoxes at run time depending on how many .rtf files exist. At the moment I have an array of 10 RichTextBoxes on the form which I fill when the form loads. This obviously restricts me to 10 templates.
Any ideas?
Thanks
Wayne
0
 

Author Comment

by:wayne_carlisle
ID: 7093714
I have changed my tact on how I am going to achieve my objective. I have been working on saving word documents as .rtf files and importing the text into RichTextBoxes. Once these files are into these RichTextBoxes I can do what I want quite successfully. However I have another problem that I would be happy to give the points away for.

This is that I now need to create RichTextBoxes at run time depending on how many .rtf files exist. At the moment I have an array of 10 RichTextBoxes on the form which I fill when the form loads. This obviously restricts me to 10 templates.
Any ideas?
Thanks
Wayne
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7900226
Hi wayne_carlisle,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

wayne_carlisle, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7978195
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now