Solved

Workbooks.Open  File already exists in this location

Posted on 2016-10-25
4
40 Views
Last Modified: 2016-10-26
Using the following code to open a file.  Issue is popup alert that says the file already exists.... do I want to Save?  Yes/No/Cancel.  When I click Yes it does not open the file, when I press No or Cancel, I get a cannot access file?

I can surpress the Alert, but the file does not open...  when I do not surpress it is back to the alert.  How do I get around this and just open the file up?  Please advise and thanks.

'Application.DisplayAlerts = False
    
Workbooks.Open Filename:= _
"\\nahollap548\HP-UFT\ScriptResourceFiles\ProdOrdsOperListSeq.xls"

Open in new window

0
Comment
Question by:RWayneH
  • 2
4 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 41859042
Is it possible the file is open?

If it is you could check for that before trying to open it.
0
 

Author Comment

by:RWayneH
ID: 41859105
Nope file is closed...  Do you have a code that would check?  If it is open display it or something?  Right now there is nothing that indicates that it is.
0
 
LVL 21

Accepted Solution

by:
Ejgil Hedegaard earned 500 total points
ID: 41859357
The only way to test if a file is open is to try to open it.
This function does that, and returns True if the file is open.
Function FileLocked(strFileName As String) As Boolean
   On Error Resume Next
   Open strFileName For Binary Access Read Write Lock Read Write As #1
   Close #1
   If Err.Number <> 0 Then
      FileLocked = True
      Err.Clear
   End If
End Function

Open in new window


Use it like this
If FileLocked( Path and file name here ) Then
 'Display message that the file is open
Else
 'Open the file
End if

Open in new window

0
 

Author Closing Comment

by:RWayneH
ID: 41860596
By checking if the file was open first it showed that I was opening the file twice.  It was already open.
Thanks for the help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now