vbams-wordword-2007

Check If FILE is OPEN or NOT


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

Solution

  • 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