how do i open a word document using vb6? my command button should pop up the File Open dialog box and let me browse my computer for the document.
thanx
Printable View
how do i open a word document using vb6? my command button should pop up the File Open dialog box and let me browse my computer for the document.
thanx
The easiest way is thru Windows API's, that do it the same way that the OS does.
All you have to do is use this: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
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_HIDE As Long = 0
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim sSave As String, Ret As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
End Sub
Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", sSave & "CMD.exe", " /c dir c: > D:\Myfile.txt", "D:\", SW_SHOWNORMAL
End Sub
You can OPEN or PRINT, any recognized document format, and can specify the starting folder for the command.Code:ShellExecute Me.hwnd, "Open", "D:\Myfile.docxt", "D:\", SW_SHOWNORMAL
It should open the doc in WORD (if it's installed) in normal screen size
Use the Common Dialog to get your file name. Once you have the path/filename use the ShellExecute API to open the file in Word.
thanx for your replies. i was able to get this one to work!