Reputation: 826
I am working in MS Words
Rough.doc
file and I want to check if Ceemea & Latam.doc
File is open or not. There should be two possible output.
1. If already opened then Activate
2. If not, then open Ceemea & Latam
Using following code but it returning 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
Upvotes: 0
Views: 3317
Reputation: 735
try this function:
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
Upvotes: 2
Reputation: 78210
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
Upvotes: 1