Solved

VB6: Printing to a .doc or .xls file

Posted on 2010-08-15
10
819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
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 add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

691 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