我正在使用MS Words
Rough.doc
文件,我想检查Ceemea & Latam.doc
文件是否已打开。应该有两种可能的输出。
1。如果已经打开,则Activate
2。如果没有,请打开Ceemea & Latam
使用以下代码但返回compile error
If AlreadyOpen("C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\CEEMEA & LATAM.doc") Then
Windows("CEEMEA & LATAM").Activate
Else
Documents.Open FileName:="C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\CEEMEA & LATAM.doc"
End If
答案 0 :(得分:1)
sub ActivateOrOpen()
on error goto nofile
Windows("CEEMEA & LATAM").Activate
exit sub
nofile:
Documents.Open FileName:="C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\CEEMEA & LATAM.doc"
end sub
答案 1 :(得分:1)
尝试此功能:
Function AlreadyOpen(filePath As String) As Boolean
Dim result As Boolean
result = False
For Each aDoc In Documents
apath = aDoc.Path + "\" + aDoc.Name
If apath = filePath Then result = True
Next aDoc
AlreadyOpen = result
End Function