Solved

Custom Printing from VB

Posted on 1999-01-14
8
148 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 69

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 69

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now