API Calls

API Calls

Anonymous
Not applicable
108 Views
2 Replies
Message 1 of 3

API Calls

Anonymous
Not applicable
I have created a form with a command button. When click I can browse through the computer and selected an excel file. I need excel to open that file. Here is the code so far:
I get an error: User-defined type not defined, then the debugger goes to the Private Sub Navigate(frm As Form, ByVal document_name As String)
ShellExecute frm.hwnd, "open", document_name, "", "", SW_SHOW

Is there another way to do this? Or how do I fix the problem.

Private Sub Cmdbrowse_Click()
Dim FileName As String
CommonDialog1.Action = 1
FileName = CommonDialog1.FileName

Navigate Me, FileName


End Sub


' Invoke the application associated with a document type
Private Sub Navigate(frm As Form, ByVal document_name As String)
ShellExecute frm.hwnd, "open", document_name, "", "", SW_SHOW
End Sub

In the module:
Public Const SW_SHOW = 1

Public 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
0 Likes
109 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
You can use GetObject() to have Excel open your file.

--
Attitudes are contagious. Is yours worth catching?
http://www.acadx.com

davidn wrote in message
news:ef375c2.-1@WebX.SaUCah8kaAW...
I have created a form with a command button. When click I can browse through
the computer and selected an excel file. I need excel to open that file.
Here is the code so far:
I get an error: User-defined type not defined, then the debugger goes to the
Private Sub Navigate(frm As Form, ByVal document_name As String)
ShellExecute frm.hwnd, "open", document_name, "", "", SW_SHOW
Is there another way to do this? Or how do I fix the problem.
Private Sub Cmdbrowse_Click()
Dim FileName As String
CommonDialog1.Action = 1
FileName = CommonDialog1.FileName
Navigate Me, FileName
End Sub
' Invoke the application associated with a document type
Private Sub Navigate(frm As Form, ByVal document_name As String)
ShellExecute frm.hwnd, "open", document_name, "", "", SW_SHOW
End Sub
In the module:
Public Const SW_SHOW = 1
Public 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
0 Likes
Message 3 of 3

Anonymous
Not applicable
A "User-defined type not defined" error typically means that
you have not reference a type library.

 

Joe

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have created a form with a command button. When click I can browse through the
computer and selected an excel file. I need excel to open that file. Here is
the code so far:
I get an error: User-defined type not defined, then the
debugger goes to the Private Sub Navigate(frm As Form, ByVal document_name As
String)
     ShellExecute frm.hwnd, "open",
document_name, "", "", SW_SHOW

Is there another way to do this? Or how do I fix the problem.

Private Sub Cmdbrowse_Click()
Dim FileName As String

CommonDialog1.Action = 1
FileName = CommonDialog1.FileName

Navigate Me, FileName


End Sub


' Invoke the application associated with a document type
Private Sub
Navigate(frm As Form, ByVal document_name As String)

     ShellExecute frm.hwnd, "open",
document_name, "", "", SW_SHOW
End Sub

In the module:
Public Const SW_SHOW = 1

Public 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

0 Likes