我一直使用vb的,vb比较熟悉,现在想开发一个小vba程序,遇到了下面这个问题:
在vb中我想根据给出的路径打开相应的文件,代码如下:
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 LongPrivate Sub Command1_Click()
Dim strFile As String
strFile =text1.text
ShellExecute Me.hwnd, "open", strFile, vbNullString, vbNullString, vbNormalFocus现在我想在VBA中实现文件打开功能,仍然使用上述代码但是却报错!提示没有Me.hwnd对象!查询Me.果然没有hwnd对象!请问这是怎么回事?在vba中到底该如何实现打开任意文件功能?请赐教!
在vb中我想根据给出的路径打开相应的文件,代码如下:
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 LongPrivate Sub Command1_Click()
Dim strFile As String
strFile =text1.text
ShellExecute Me.hwnd, "open", strFile, vbNullString, vbNullString, vbNormalFocus现在我想在VBA中实现文件打开功能,仍然使用上述代码但是却报错!提示没有Me.hwnd对象!查询Me.果然没有hwnd对象!请问这是怎么回事?在vba中到底该如何实现打开任意文件功能?请赐教!
Dim strFile As String
strFile =text1.text
ShellExecute 0, "open", strFile, vbNullString, vbNullString, vbNormalFocus
第二个参数用vbNullString就相当于双击打开文件了ShellExecute 0, vbNullString, strFile, vbNullString, vbNullString, vbNormalFocus