Solved

Excel opened as 'read only'

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

920 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now