Solved

Excel opened as 'read only'

Posted on 2007-11-14
3
1,099 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
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 250 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA modules import 4 52
Multiple (nested?) IF statements with AND / please help - Too many arguments 8 42
Turn date into age 17 31
V-Lookup 11 8
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

792 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