|
-
January 20th, 2009, 08:03 PM
#1
open a word document...
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
-
January 20th, 2009, 08:17 PM
#2
Re: open a word document...
The easiest way is thru Windows API's, that do it the same way that the OS does.
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
All you have to do is use this:
Code:
ShellExecute Me.hwnd, "Open", "D:\Myfile.docxt", "D:\", SW_SHOWNORMAL
You can OPEN or PRINT, any recognized document format, and can specify the starting folder for the command.
It should open the doc in WORD (if it's installed) in normal screen size
-
January 20th, 2009, 08:59 PM
#3
Re: open a word document...
 Originally Posted by dglienna
The easiest way is thru Windows API's, that do it the same way that the OS does.
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
All you have to do is use this:
Code:
ShellExecute Me.hwnd, "Open", "D:\Myfile.docxt", "D:\", SW_SHOWNORMAL
You can OPEN or PRINT, any recognized document format, and can specify the starting folder for the command.
It should open the doc in WORD (if it's installed) in normal screen size
thanx for your reply. but, i need to open a doc - not from a specific folder. it could be anywhere on the computer or on the network. the program should pop up a dialog box where i can browse for the file and then open it. how is this possible?
-
January 20th, 2009, 10:01 PM
#4
Re: open a word document...
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.
-
January 24th, 2009, 11:36 PM
#5
Re: open a word document...
thanx for your replies. i was able to get this one to work!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|