Solved

Opening Office Apps  from within VB

Posted on 2000-03-16
6
166 Views
Last Modified: 2010-05-02
How do you open up any Office document from within VB6.0?
We can open up a Word or Excel document on their own, but we want to add the functionality of allowing the user to open ANY Office document (Project/Word/Excel etc...).
We've tried using "Set pword = CreateObject("office.application")", and adding the Microsoft Office Reference, but to no avail. Please help. Cheers.
0
Comment
Question by:TGB
6 Comments
 

Accepted Solution

by:
PatriceF earned 100 total points
ID: 2622880
You can use something like this

Dim objApp as Object
Dim strAppclass as string

Select case strFileExt

 case "XLS" ,"XLT"
      strAppClass ="Excel.Application"

 case "DOC", "DOT"
      strAppClass ="Word.Application"
 
  case ...
end Select

 set objApp = CreateObject (strAppClass)

But then the open method are different for each application like:
Word : Word.documents.Add
Excel : Excel.Workbook.add  

So you're stuck with Select -case statements...
0
 

Author Comment

by:TGB
ID: 2622904
This looks good, but what is strFileExt
defined as?
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2622912
I think I understand your question.. as such I will only prototype it out for you..

1. Add a Tab strip to a form.. Label the tabs Access, Excel, Outlook, Project, Word.
2. For each of the Tab Strip Frames, add a Listbox, and a command button for open.
3. Using FSO.. recursively scan the hard drive.. testing the file extension of each file. Place the the path of all MDB extensions into the Access Listbox.. XLS into the Excel Listbox.. DOC for Word.. (Project and Outlook I don't know right off the top of my head)
4. When the user clicks the Word Tab, a list of all DOC files on the disk will appear.. by clicking on a file path and then clicking on the Open button.. (or if you want.. setup a double click on the Listbox to do both at once).. depending on what Frame you are on..

If you are on the Word Tab..
SHELL "c:\pathname\WORD.EXE " & Listbox.SelectedItem

Excel..
SHELL "c:\pathname\EXCEL.EXE " & Listbox.SelectedItem

etc.. etc.

----------------------------------
I'm guessing that is what you have in mind, right? Anyhow.. I am off to dreamland.. good luck.. <smile>.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:PatriceF
ID: 2622954
strFileExt is the extension of the file
like
strFileExt = ucase(right(strFileName,3))

where strFileName = "MyDocument.doc" for example
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2623326
You can use the WebBrowser Control and call the NavigateTo method, supplying the Path to the File. The Document will be opened in the Browser (whenever the Office App is installed).
Components: Microsoft Internet Controls
BTW: This allows you not only to open Office Documents only...
0
 
LVL 1

Expert Comment

by:pclement
ID: 2624079
You can open any document with a registered file extension using the ShellExecute API function call. If you do not require automation functionality  (control of the application) this is the best route to take. See the following for an example:

http://support.microsoft.com/support/kb/articles/Q170/9/18.asp

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…

758 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

18 Experts available now in Live!

Get 1:1 Help Now