how to know the picture is open

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using MS Office 2003 and writing VBA in Excel.

I have a picture which is not inserted in Excel and saves in a folder. I
want to know if the picture is opening or not. Because I have to make sure
the picture is not opening before renaming it.

Do you have any solution to know if the picture is opening?
Appreciate for your kind post.
 
Microsoft has an IsFileOpen function at:
http://support.microsoft.com?kbid=138621

But when I opened some .jpg's in various programs (irfanview, paint, imaging),
the file showed not in use. I could even delete it.

Could you try to just rename it and then check to see if it was successful:

Option Explicit
Sub testme()

Dim MyOldFileName As String
Dim myNewFileName As String

MyOldFileName = "c:\my documents\my pictures\keyboard2.jpg"
myNewFileName = "c:\my documents\my pictures\keyboard.jpg"

If Dir(MyOldFileName) = "" Then
MsgBox "It's not there!"
Else
On Error Resume Next
Name MyOldFileName As myNewFileName
If Err.Number <> 0 Then
MsgBox "Rename failed, it may be in use elsewhere"
Err.Clear
End If
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top