Solved

Launch Word/Excel from VB

Posted on 1998-12-21
3
181 Views
Last Modified: 2011-09-20
I need to open a Microsoft Word document or a Microsoft
Excel spreadsheet from my VB application when the user
clicks a control button. The document or spreadsheet to
open will be stored as data in a Microsoft SQL Server
database.

Once "Word" or "Excel" is opened the user should be able
to select a new document or spreadsheet to view without
closing "Word" or "Excel".

I need the code to put in the click event of the button
to make this happen.

Visual Basic 5.0 Enterprise. Microsoft SQL Server 6.5.
Word and Excel 97.
0
Comment
Question by:Melvin
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
mukvij earned 100 total points
ID: 1451727
Following is code for activating Excel and Word:

Private Sub Command1_Click()
Dim objExcel As Excel.Application
Dim objWord As Word.Application
Set objExcel = New Excel.Application
objExcel.Workbooks.Add
Set objWord = New Word.Application
objWord.Documents.Add
objExcel.Visible = True
objWord.Visible = True

End Sub


Each time you click Command1 a new instance of Word and Excel  is activated. User can use Excel or word to view any files. To use same instance everytime use:
set objexcel=getobject("","Excel.application")

in place of

Set objExcel = New Excel.Application
0
 

Author Comment

by:Melvin
ID: 1451728
If I want to open c:\data\excel\my.xls when I start Excel, how would I do it?

If I want to open c:\data\word\my.doc when I start Word, how would I do it?

Once Excel or Word is already running, how would I start my2.xls or my2.doc?

0
 
LVL 1

Expert Comment

by:mukvij
ID: 1451729

You have to replace two lines in code . Following is the changed code:

Private Sub Command1_Click()
Dim objExcel As Excel.Application
Dim objWord As Word.Application
Set objExcel = New Excel.Application
objExcel.Workbooks.Open "c:\data\excel\my.xls"
Set objWord = New Word.Application
objWord.Documents.Open "c:\data\word\my.doc"
objExcel.Visible = True
objWord.Visible = True
End Sub

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

21 Experts available now in Live!

Get 1:1 Help Now