Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Launch Word/Excel from VB

Posted on 1998-12-21
3
Medium Priority
?
188 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
[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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
mukvij earned 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

688 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