?
Solved

Excel opened as 'read only'

Posted on 2007-11-14
3
Medium Priority
?
1,104 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 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
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…

850 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