Solved

Launch Word/Excel from VB

Posted on 1998-12-21
3
187 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

624 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