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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching MS Word with VB

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello friend
I want to open an MS Word file on button click event. Idont want to sow that file in my application rather let ms word open it for me. can any one plz tell me the way. Thanks in advance.

saddysan
 
There is a "shell" command to fire Word, with the word document:
shell "c:\program files\winword\winword.exe c:\files\document.doc"

for example, but the .exe would have to be in the same place on each machine you use the program - could you guarantee that?

A better way is to use the file association within windows, for which you need the API system.

Declare Function shellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal fsShowCmd As Long) As Long

Function gfn_shellExecute(DocName As String) As Long
gfn_shellExecute = shellExecute(me.hwnd, "Open", DocName, "", "C:\", SW_SHOWNORMAL)

End Function


In your program just call:
dim result as long
result = gfn_shellExecute("c:\my documents\document.doc")


Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top