Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6: Printing to a .doc or .xls file

Posted on 2010-08-15
10
Medium Priority
?
826 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

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…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
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…
Suggested Courses

610 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