Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Launch Word/Excel from VB

Posted on 1998-12-21
3
Medium Priority
?
189 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 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

963 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