Using Shell with Excel

  • Thread starter Thread starter BigRuss
  • Start date Start date
B

BigRuss

How do I use the Shell command to open an Excel file (named "MyFile.xlsx"),
with read-only status?

Any help would be appreciated. -- Russ
 
How do I use the Shell command to open an Excel file (named "MyFile.xlsx"),
with  read-only status?

Any help would be appreciated.  -- Russ

Hi,

You can apply Read-only attribute to excel file using:

"System.IO.File.SetAttributes" method.

...then launch it using Process.Start to open Excel file as read-only
instead of Shell as follows:

//////////////
' Get current attributes of the file
Dim currentAttr As System.IO.FileAttributes = _
My.Computer.FileSystem.GetFileInfo("c:\MyFile.xlsx").Attributes

' Apply read-only attribute
System.IO.File.SetAttributes("c:\MyFile.xlsx", _
IO.FileAttributes.ReadOnly Or currentAttr)

' Launch it
Process.Start("c:\MyFile.xlsx")
\\\\\\\\\\\\\\

Hope this helps,

Onur Güzel
 
Back
Top