Solved

Opening a word doc with cmdlgOpenFile

Posted on 1998-12-11
2
216 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
ID: 1449533
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
ID: 1449534
'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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 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