Solved

Custom Printing from VB

Posted on 1999-01-14
8
152 Views
Last Modified: 2010-05-03
I want to print a standard letter from VB. I want to be able to change "fields" in this letter at runtime before I print it. For example: I have a MSWord doc all nicely formatted and including some graphics, but now I want to change the name/address etc and only then print it. I'm using VB6 (VisStudio).
0
Comment
Question by:ayrezyle
8 Comments
 
LVL 1

Expert Comment

by:wford
ID: 1456483
You can do this buy getting control of the word application as an object and then useing VBA to Load the file, Insert name and address into the field then tell it to print.

If this sound right I can post you some code
0
 
LVL 14

Expert Comment

by:waty
ID: 1456484
You could try the PrintPreview OCX. It will do what you need.

http://www.geocities.com/ResearchTriangle/6311/
0
 
LVL 1

Expert Comment

by:ikxsoft
ID: 1456485
try using the rich edit control to load the file, then change the field and print
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:ayrezyle
ID: 1456486
I still don't know *how* to edit those fields. I want to do some funky DTP and only then edit those fields. That implies that this RTF control must support inserted images with text over backgrounds, etc. Thus for ikxsoft's answer to be accepted, I need code that shows *how* to edit fields and how do I initialise the RTF doc. With Word I assume, but what/how/where those fields I wanna change?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 1456487
Create bookmarks in your MSWord document. Then open this document from VB using automation. Replace the bookmarks with your values. Launch the print.

Try this code snippet:
Private Sub Command1_Click()
Dim objWord As Word.Application

    Set objWord = New Word.Application
    With objWord
        .Visible = True
        .Documents.Open "c:\test.doc"
        .ActiveDocument.Bookmarks.Item("aa").Select
        .Selection.InsertAfter "Hello"
        .PrintOut
        .Quit False
    End With
    Set objWord = Nothing
End Sub

0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1456488
ummm, problem. For some reason, when I run the code above, I get the error "User-defined type not defined" with "Word.Application" highlighted <spelling?> Where/how do I get it to recognise that object type?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 1456489
In the Project References, you have to select Microsoft Word Object Library.
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1456490
Yep, that was it! Thanks!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

696 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