Solved

VB6: Printing to a .doc or .xls file

Posted on 2010-08-15
10
811 Views
Last Modified: 2013-12-24
How do I write text to a .doc or .xls file?

Possible  printer objects include Adobe, since Adobe is a "printer". But I want to "print" to a word document, or an excel spreadsheet.
0
Comment
Question by:NormaPosy
  • 6
  • 3
10 Comments
 
LVL 16

Expert Comment

by:carsRST
ID: 33440870
You'll need Excel installed on the machine.  

In your references, make a reference to Microsoft Excel Object Library.

Then try this code, as an example:

Dim app As New Excel.Application
Dim wb As New Workbook

Set wb = app.Workbooks.Add

wb.ActiveSheet.Cells(1, 1) = test
0
 
LVL 16

Expert Comment

by:carsRST
ID: 33440877
For Word, you would do the same type of thing, but make a reference to the Microsoft Word Object library.

0
 

Author Comment

by:NormaPosy
ID: 33442371
I get an error messagebox:
"User-defined type not defined"

With "app As New Excel.Application" highlighted.

I have Microsoft Office on my machine. Coding in VB6 under XP.
0
 
LVL 16

Expert Comment

by:carsRST
ID: 33442441
Did you add a reference (within vb references) to the Excel object?

0
 
LVL 16

Expert Comment

by:carsRST
ID: 33442452
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 16

Expert Comment

by:carsRST
ID: 33442458
Sorry, last one was to add user control.  But anyway, adding reference should be something along the image below.

0
 
LVL 16

Expert Comment

by:carsRST
ID: 33442459
0
 

Author Comment

by:NormaPosy
ID: 33442808
I will try that and get back to you.

Meantime: I am doing my VB development on an external hard drive. My Microsoft Office lives on the machines own internal hard drive. Does this matter?

It occured to me that it might matter.
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33442969
Or you can use CreateObject without adding the reference:

Dim xlsApp as Object
Set xlsApp = CreateObject("Excel.Application")

0
 

Author Comment

by:NormaPosy
ID: 33450546
Thank you.

By the way: It doesn't matter if the VB application is on one drive, and Microsoft Office is on another drive.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

911 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

20 Experts available now in Live!

Get 1:1 Help Now