Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Is File Folder Open
Eduardo Benaim 
     
16 months ago
Can anyone provide a function to check if a File folder is open on the Desktop using VBA?  This is so I don't open multiple instances of the File folder.
Alex Hedley  @Reply  
           
16 months ago
Check If a File Is Already Open
http://www.vbaexpress.com/kb/getarticle.php?kb_id=468
Untested

DetailsFunction IsFileOpen(FileName As String)
    Dim iFilenum As Long
    Dim iErr As Long
    
    On Error Resume Next
    iFilenum = FreeFile()
    Open FileName For Input Lock Read As #iFilenum
    Close iFilenum
    iErr = Err
    On Error GoTo 0
    
    Select Case iErr
    Case 0:    IsFileOpen = False
    Case 70:   IsFileOpen = True
    Case Else: Error iErr
    End Select
    
End Function


DetailsSub test()
    If Not IsFileOpen("C:\MyTest\volker2.xls") Then
        Workbooks.Open "C:\MyTest\volker2.xls"
    End If
End Sub
Alex Hedley  @Reply  
           
16 months ago
check if a folder is open (vba)
Untested
DetailsSub test1()
        Dim OpenFold As Variant
        Dim oShell As Object
        Dim Wnd As Object
        Dim strFolder

        OpenFold = "mysubfolder"
        strFolder = "U:\myfolder\" & OpenFold
        Set oShell = CreateObject("Shell.Application")

        For Each Wnd In oShell.Windows
            If Wnd.Name = "Windows Explorer" Then
               If Wnd.Document.Folder.Self.Path = strFolder Then Exit Sub
            End If
        Next Wnd
        Application.ThisWorkbook.FollowHyperlink Address:=strFolder, NewWindow:=True
End Sub

Source: https://stackoverflow.com/a/17097610
Eduardo Benaim OP  @Reply  
     
16 months ago
Alex. Thank you. The sub sent checks for a "myFile.ext" This I get.

I am looking to find if a File Folder is open on the desktop NOT a File.
This to check if  c:\...mydesktop\myFolder\ is open on the desktop.  (Folder It must exist)
The question is if the folder is already opened on the desktop.
Kevin Robertson  @Reply  
           
16 months ago
Alex has supplied code for both Files AND Folders.
Eduardo Benaim OP  @Reply  
     
16 months ago
I saw the stack overflow which addresses if an Application s open.

to be precise I have a folder:
C:\Users\Benai\Desktop\EdasduardoBenaim

I need to check if it is open or closed.
If closed I will open it, If closed I don't need to open an other instance
Eduardo Benaim OP  @Reply  
     
16 months ago
Thank you Alex.
can you point me in this direction.  
I checked the code vault but did not see it
Eduardo Benaim OP  @Reply  
     
16 months ago
Do you remember a lesson , template or course where this is?
Eduardo Benaim OP  @Reply  
     
16 months ago
I remember checking if a Folder Exists, but not if is Open
Alex Hedley  @Reply  
           
16 months ago
Access Developer 30
Classic VB File I/O. Reading & Writing Text Files
Eduardo Benaim OP  @Reply  
     
16 months ago
Thank you Alex. I tested your code
In my Computer:
1    Wnd.Name = "File Explorer"
2    Application.ThisWorkbook.FollowHyperlink Address:=strFolder, NewWindow:=True
what would be ThisWorkbook?

The Code is checking if the Directory Exists.
I need to check if it is Open in the Desktop
What am I missing??
Alex Hedley  @Reply  
           
16 months ago
ThisWorkbook usually related to Excel. You'll probably need to update accordingly.

Did you update OpenFold and strFolder?
Richard Rost  @Reply  
          
15 months ago
Eduardo Benaim I've had questions similar to this on my to-do TechHelp list forever. I'll bump them up the list.

Alex - thanks for the code. I tested and verified that they work (with some minor tweaks). Adding to the Code Vault soon.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 9:38:14 AM. PLT: 0s