Solved

Workbooks.Open  File already exists in this location

Posted on 2016-10-25
4
58 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 22

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

685 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