Solved

Workbooks.Open  File already exists in this location

Posted on 2016-10-25
4
65 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 34

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

726 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