Solved

Launch Word/Excel from VB

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

809 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