|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- '检查文档是否打开
- Function JcDk(Optional Mc As Variant) As String
- Dim Wd(1 To 3) As Variant, Wrk As Workbook
- If Len(Mc) = 0 Then
- Debug.Print "检查文档是否打开 不处理为空的路径!"
- Else
- Wd(1) = Mid(Mc, InStrRev(Mc, "") + 1, Len(Mc) - InStrRev(Mc, "")) '工作薄名称
- Wd(2) = Mid(Mc, 1, InStrRev(Mc, "") - 1) '工作薄路径
- For Each Wrk In Workbooks
- With Wrk
- If .Name = Wd(1) Then
- If .Path = Wd(2) Then
- JcDk = Wd(1)
- Else
- MsgBox "请关闭相同名称的工作薄“" & Wd(1) & "”", 16
- JcDk = "Err"
- End If
- Exit For
- End If
- End With
- Next Wrk
- End If
- Set Wrk = Nothing
- End Function
- '文档打开自定义函数
- Function DkWd(Optional Mc As Variant) As String
- ' On Error Resume Next
- Dim Wrk As Workbook
- Dim Wd(1 To 2) As Variant
- Wd(1) = Mid(Mc, InStrRev(Mc, "") + 1, Len(Mc) - InStrRev(Mc, "")) '工作薄名称
- Wd(2) = Mid(Mc, 1, InStrRev(Mc, "") - 1) '工作薄路径
- Set Wrk = GetObject(Mc)
- If Wrk Is Nothing Then
- DkWd = "Err"
- MsgBox "无法打开工作薄“" & Wd(1) & "”", 16
- Else
- DkWd = Wd(1)
- End If
- Set Wrk = Nothing
- End Function
复制代码 |
|