Home All Groups Group Topic Archive Search About

Using Shell with Excel

Author
1 Jul 2009 10:20 PM
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

Author
3 Jul 2009 4:11 PM
Onur_Güzel
On Jul 2, 1:20 am, BigRuss <BigR***@discussions.microsoft.com> wrote:
> 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
Author
4 Jul 2009 6:58 AM
BigRuss
Thank you Onur!  I will give this a try.

Russ

==============

Show quoteHide quote
"Onur Güzel" wrote:

> On Jul 2, 1:20 am, BigRuss <BigR***@discussions.microsoft.com> wrote:
> > 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
>