Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check to see if Excel file is already open

Status
Not open for further replies.

blckngldhwk

Technical User
Feb 14, 2008
46
US
I have programmed this type of command for IE in the past but am having problems getting it to work for Excel.

I'm wanting to check to see if a particular file is already open. If it is open I want to activate it, otherwise I want to open it.

Here is the code that I have used for IE, can you advise how to modify for Excel?

Code:
Set oIE = Nothing
      
          Set oApp = CreateObject("Shell.Application")
           
          For iApp = 1 To oApp.Windows.Count
        
          Set oWin = oApp.Windows(iApp - 1)
      
          If InStr(oWin.Name, "Windows Internet Explorer") Then
          
          sURL = oWin.LocationURL
        
          On Error Resume Next      
                
          Set oTitle = oWin.Document.GetElementsByTagName("title")
       
          On Error Goto 0
       
          If Not oTitle Is Nothing Then
        
               If oTitle(0).innerHTML = "WindowName" Then                   
                    Set oIE = oWin
        
                    AppActivate "WindowName"
          
                    End With
 



Check out the VBA Help in Excel on GetObject. Has good examples.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top