Solved

VB6: Printing to a .doc or .xls file

Posted on 2010-08-15
10
810 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

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…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

18 Experts available now in Live!

Get 1:1 Help Now