Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Open a word doc from VB6 1

Status
Not open for further replies.

itmasterw

Programmer
Apr 13, 2003
147
US
Hi, I am not sure what I need to do here, but I am trying to open a word Doc, which gives the user instructions, but it is not working. This is waht I use in Access VBA, do I need something different in VB6.?

Shell ("WinWord.exe J:\APPSUPT\Procedure\MersMonthlyStats.doc")

Thank you
 
Hi,

Try ShellExecute:
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Dim res as Long

Private Sub Command1_Click()
    res = ShellExecute(hWnd, vbNullString, "J:\APPSUPT\Procedure\MersMonthlyStats.doc", vbNullString, vbNullString, vbNormalFocus)
    If res <> 33 Then ' a successful file open
        MsgBox "YOUR GENERIC ERROR CODE ETC", vbCritical, "File Error"
        Exit Sub
    End If
End Sub

Hope this helps


Harleyquinn

---------------------------------
For tsunami relief donations
 
Here is a simpler solution:
Code:
Sub OpenDoc(File As String)
  With CreateObject("Word.Application")
    .Visible = True
    .Documents.Open File
  End With
End Sub

Use:
Code:
Private Sub Command1_Click()
  OpenDoc "c:\test.doc"
End Sub



Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Or:

Shell "RUNDLL32.EXE URL.DLL, FileProtocolHandler c:\test.doc" , vbNormalFocus

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top