Hi,
I would like to open up a MS Word Document (or another file) by clicking on a command button.
Can anyone please tell me what code can I put in the command button for this?
I don't wish to use the OLE function.
Rastin
Printable View
Hi,
I would like to open up a MS Word Document (or another file) by clicking on a command button.
Can anyone please tell me what code can I put in the command button for this?
I don't wish to use the OLE function.
Rastin
Use the ShellExecute API function.
Put the following in the General Declaration section of your form.Then in the click event of a button use code simular to this:VB Code:
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 LongBest regardsVB Code:
Private Sub Command1_Click() ShellExecute Me.hwnd, "Open", "c:\TheFileToOpen.doc", "", "", vbNormalFocus
Another method would be to shell WinWord and pass the filename as the command line argument, e.g.
Code:Shell "Winword myfile.doc", 1