|
本帖最后由 weiyingde 于 2016-9-20 08:18 编辑
我的代码这样写,却没有任何反应,赵老师帮我看看,代码如下:
Private Declare Function MessageBoxTimeout Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long, ByVal wlange As Long, ByVal dwTimeout As Long) As Long '申明自动关闭对话框
sub 避免重复的打开优盘文件()
On Error Resume Next
Call 检测优盘
myfil = "H:\ofenused\课堂答问记分系统.xslm"
If Dir(myfil) Then
s = "该处没有文档"
MessageBoxTimeout 0, s, Space(5) & "温馨提示", 0, 1, 2000
Exit Sub
Else
Set xlapp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set xlapp = CreateObject("Excel.Application")
Dim wbXL As excel.Workbook
xlapp.Workbooks.Open myfil
xlapp.Visible = False
xlapp.DisplayAlerts = False
Set wbXL = xlapp.Workbooks.Activate
arr = wbXL.Sheets("名单").Range("A1:A" & [A65536"].End(3).Row)
Else
For Each wb In Workbooks
If wb.Name = myfil Then
Set wbXL = xlapp.wb.Activate
arr = wbXL.Sheets("名单").Range("A1:A" & [A65536"].End(3).Row)
Exit For
End If
Next
end if
End If
xlapp.DisplayAlerts = False
Debug.Print UBound(arr)
End Sub
Sub 检测优盘()
Application.DisplayAlerts = False
Dim s$, ilj$, ipth$, msg1$, msg2$, msg3$
Set yy = CreateObject("sapi.spvoice")
ipth = Split(ActivePresentation.Path, ":")(0) & ":"
msg1 = "请插入优盘!"
msg2 = "请将优盘符改为H:"
msg3 = "请在H盘中运行本文档!"
For Each f In CreateObject("Scripting.FileSystemObject").Drives
If f.drivetype = 1 Then s = f.Path: Exit For
Next
If s <> "" Then
If s = "H:" Then
If s <> ipth Then
MessageBoxTimeout 0, msg3, Space(3) & "友情提示", 0, 1, 1000
yy.Speak msg3
ActivePresentation.Close
Application.Quit
End If
Else
MessageBoxTimeout 0, msg2, Space(3) & "友情提示", 0, 1, 1000
yy.Speak msg2
ActivePresentation.Close
Application.Quit
End If
Else
MessageBoxTimeout 0, msg1, Space(3) & "友情提示", 0, 1, 1000
yy.Speak msg2
ActivePresentation.Close
Application.Quit
End If
End Sub
|
|