Link to home
Start Free TrialLog in
Avatar of evault
evaultFlag for United States of America

asked on

Excel opened as 'read only'

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

Avatar of RobSampson
RobSampson
Flag of Australia image

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.
ASKER CERTIFIED SOLUTION
Avatar of imitchie
imitchie
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Open Excel Read/Write