Solved

Opening a word doc with cmdlgOpenFile

Posted on 1998-12-11
2
214 Views
Last Modified: 2008-02-01
How do i open a Word or Excel document in its environment
with a cmdlgOpenFile
0
Comment
Question by:poire
2 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 50 total points
Comment Utility
First use the Common Dialog control to create a common dialog.
Now start the selected document using the function "Shell". Just pass the document name as application to start.
0
 

Expert Comment

by:dbiener
Comment Utility
'get file name from common dialog control ( you can use api calls if you want)

    CommonDialog1.CancelError = True
    On Error GoTo CatchError
    CommonDialog1.Flags = cdlOFNHideReadOnly
    CommonDialog1.Filter = "Word Files (*.doc)|*.doc"
    CommonDialog1.FilterIndex = 1
    CommonDialog1.ShowOpen

    'now open the file in word (easy)
    shell "C:\Program Files\Microsoft Office\Office\WINWORD.EXE CommonDialog1.filename"

   
CatchError:
    'user clicked on cancel
    Exit Sub



    'or better way
    Private Const SW_SHOWNORMAL = 1
    Declare Function ShellExecute Lib "SHELL" (ByVal hwnd%, _
       ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, _
       ByVal lpszDir$, ByVal fsShowCmd%) As Integer

    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", _  
        CommonDialog1.filename, "", "C:\", SW_SHOWNORMAL)


0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

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

763 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

16 Experts available now in Live!

Get 1:1 Help Now