|
发表于 2012-8-17 21:58
|
显示全部楼层
本楼为最佳答案
- 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 Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
- Dim rng
- Set rng = Range("a2:a" & Range("a65536").End(3).Row)
- If Not Application.Intersect(Target, rng) Is Nothing Then
- If Dir(ThisWorkbook.Path & "" & Target.Value) = "" Then
- MsgBox "该文件夹下没有此文件!请检查" & Chr(10) & "文件名称是否正确!", vbCritical, "错误提示"
- Exit Sub
- End If
- If Target.Value = ThisWorkbook.Name Then
- MsgBox "当前文件已经打开!", vbExclamation, " 提示"
- Cancel = True
- Exit Sub
- End If
- On Error Resume Next
- If InStr(UCase(Target.Value), ".XLS") <> 0 Then
- Workbooks.Open ThisWorkbook.Path & "" & Target.Value
- Else
- ShellExecute 0, "open", Target.Value, "", ThisWorkbook.Path & "", 5
- End If
- Cancel = True
- End If
- End Sub
复制代码 代码在汇总表(在我电脑上打开EXCEL文件总是有点问题,所以加上了workbooks.open方法)
|
评分
-
查看全部评分
|