Solved

VB6: Printing to a .doc or .xls file

Posted on 2010-08-15
10
813 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

772 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