?
Solved

Excel opened as 'read only'

Posted on 2007-11-14
3
Medium Priority
?
1,102 Views
Last Modified: 2008-02-01
I have the attached code below, whic searches for an excel file and then opens the one it finds. However, it opens as a read only file. I need it to open as read-write. Can someone please explain to me what, in the code, is causing the read-only status and how to resolve it?
For Each FoundFile As String In My.Computer.FileSystem.GetFiles(My.Settings.DefFolder, _
        FileIO.SearchOption.SearchAllSubDirectories, "*.xls")
            ' add each found file to the list box
            ' search each file for the specified string
            Dim xlApp As Object = CreateObject("Excel.Application")
            Dim xlWB As Object = xlApp.Workbooks.Open(FoundFile)
            Dim xlWS As Object = xlWB.Worksheets("Sheet1")
            Dim xlFndCell As Object = xlWS.Cells.Find(SearchBox.Text, , -4163, 1)
            If Not xlFndCell Is Nothing Then
                If xlWS.range("E21").value.ToString = SearchBox.Text Then
                    FileNm = """" + FoundFile + """"
                    ProcID = Shell("C:\Program Files\Microsoft Office\Office\excel.exe " & FileNm, AppWinStyle.NormalFocus)
                    ' Activate the application.
                    AppActivate(ProcID)
*** At this point the Excel file opens as a read-only

Open in new window

0
Comment
Question by:evault
[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
3 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 20286209
By default, the only reason it would open in read-only mode is if was already open by another process before attempting to open it.  There is a command line switch to force read-only, so without that, you would assume it would open in read-write whenever possible.

http://support.microsoft.com/kb/291288

Regards,

Rob.
0
 
LVL 25

Accepted Solution

by:
imitchie earned 750 total points
ID: 20288431
does
Dim xlWB As Object = xlApp.Workbooks.Open(FoundFile)
open it once (non-visible), and
ProcID = Shell("C:\Program Files\Microsoft Office\Office\excel.exe " & FileNm, AppWinStyle.NormalFocus)
a second time? (different process caused by shell)
0
 

Expert Comment

by:Bacliff
ID: 20586581
Open Excel Read/Write
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

741 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