?
Solved

Problem opening Excel files in edit mode

Posted on 2006-04-12
5
Medium Priority
?
828 Views
Last Modified: 2008-02-01
Hi experts,
I have a problem opening an Excel file in edit/non-edit mode, using the following VB code statements:

1)     Set mExcelWorkbook = excelApp.Workbooks.Open(FileName:=sFileName, ReadOnly:=True)
2)     Set mExcelWorkbook = excelApp.Workbooks.Open(FileName:=sFileName)

By that I mean if statement 1) is executed and I try to open the (sFileName) using Excel, I get a message saying that file is locked for editing. Why?
If however I first open the file using Excel and then run my application, executing statement 1), I don't get any warnings. To me that suggests that VB doesn't see any problems opening (an already open) file because it is not trying to edit the file so all is OK.

If I use statement 2 and repeat the same exercise, I get the same result; which doesn't make sense to me. If the file is already open by Excel (in edit mode) then I should get an error executing statement2, shouldn't I?

Can someone tell me what should my statement be to open a file in ReadOnly mode so that I don't get a warning message in Excel application?

Thanks,
     Michael
0
Comment
Question by:gem56
  • 3
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 250 total points
ID: 16453530
Hi Michael,

I've encountered similar things in the past, sometimes I find it helps to not use Named arguments, like:
 Set mExcelWorkbook = ExcelApp.Workbooks.Open(sFileName, , True)

If need be, you could even suppress the warning messages while opening (in case someone has it open, it will probably still prompt you):
 ExcelApp.DisplayAlerts = False
 Set mExcelWorkbook = ExcelApp.Workbooks.Open(sFileName, , True)
 ExcelApp.DisplayAlerts = True

Matt
0
 

Author Comment

by:gem56
ID: 16604629
Hi mvidas,
Sorry for not getting back earlier. I tried your suggestion as soon as you made it but it didn't seem to make any difference and I got carried away with remaining issues and development and simply forgot to respond, again sorry.

As I said, I still get the same thing happening but thanks for pointing out that in some cases not using Named arguments helps so on closing I'll give you some points, unless you have any further suggestion.

/Michael
0
 
LVL 35

Expert Comment

by:mvidas
ID: 16648102
The delay isn't a problem, Michael, I was actually not available myself due to a few medical issues so I wouldnt have been able to get back to you sooner anyways (unless it was the morning you asked the question).
I have noticed that sometimes these read only / edit mode messages don't follow normal logic when you're accessing a file on a network/shared drive.  
Unfortunately I don't really know a good workaround, but you may want to post a 20-point question at http://www.experts-exchange.com/Applications/MS_Office/Excel/ as a 'pointer' to this question, get some fresh eyes looking at this question.  Add something in there to only comment in this (original) question, then when this is resolved you can just delete your pointer question.  Might be worth a try!
Matt
0
 

Author Comment

by:gem56
ID: 16648551
Thanks mvidas for your suggestion, I'll do that.
/Michael

0
 

Author Comment

by:gem56
ID: 16841041
Hi mvidas,
I gave you the points and only Average rating because it didn't resolve my problem however I did learn something from your response that I didn't know previously.
/Michael
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

840 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