Solved

Workbooks.Open  File already exists in this location

Posted on 2016-10-25
4
26 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
Comment Utility
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
Comment Utility
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 20

Accepted Solution

by:
Ejgil Hedegaard earned 500 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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

10 Experts available now in Live!

Get 1:1 Help Now