Solved

Custom Printing from VB

Posted on 1999-01-14
8
150 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 111
Modifying Conditional Format from VBA code 3 57
TT Auto Dashboard 13 92
Added a column screws up code 5 57
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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