Determining if user has "write/save" permissions

  • Thread starter Thread starter Everett
  • Start date Start date
E

Everett

Hello All!

I am using Excel 2000 and I have a question.

I have a program (Delphi) which makes a call that executes
an excel macro. The macro does nothing more than change
the value of the "zooming/scaling" value from whatever it
is to 100%. For some users, who don't have WRITE/SAVE
access to the directory where the .xls files live, the
newly modified .xls file gets saved into the "My
Documents" folder instead of the network drive where
the .xls originally was opened. My question is, is there
a way to determine if a user has the "proper rights" for
the original folder where the .xls resides?

I want to be able to throw up a warning message in those
cases where the user does not have "write/save" right for
the directory where the .xls is located.


Thanks in advance for all suggestions and replies!

Everett
 
Are you sure you're specifying the correct drive and folder? I've never seen
excel just change to a different when I specify where I want it saved.

Maybe you could toss in some error checking:

Option Explicit
Sub testme()

Dim mySaved As Boolean

mySaved = ActiveWorkbook.Saved
ActiveWorkbook.Saved = False 'make it dirty

On Error Resume Next
ActiveWorkbook.SaveAs "C:\my documents\excel\book1.xls"
On Error GoTo 0

If ActiveWorkbook.Saved Then
'it did it ok
Else
MsgBox "couldn't save workbook"
ActiveWorkbook.Saved = mySaved 'put it back to what it was
End If

End Sub

You could even look at:

if err.number <> 0 then

to see if the saveas succeeded.
 
With some versions of excel, File|saveAs will go to the same folder as the
original workbook.

With earlier versions (xl97, if I remember correctly), will go back to the
user's default folder.

It kind of sounds like you're supporting multiple versions. I think I'd make
sure I specified the intended folder:

dim myPath as string
dim wkbk as workbook
set wkbk = workbooks.open(filename:=....,etc)
on error resume next
wkbk.saveas filename:=wkbk.path & "\" & "someothername.xls"
'rest of error stuff.

But if you're really just opening, fixing and closing, you can just do a

wkbk.save
(wrapped nicely with error checking.)

====
Did I read an invisible File|SaveAs into your first message? It seems to have
disappeared when I reread it!

======

When someone opens that workbook without update capability, do they see
[ReadOnly] in the workbook's title bar?

That's the way I remember it working for me when I can't update a file. Excel
respects those windows/OS settings.

Maybe you could just check the .readonly property.

If ActiveWorkbook.ReadOnly Then
'don't do it
Else
ActiveWorkbook.Save
End If



Good Afternoon Dave and Thanks for your reply!

I am not specifying the drive and folder at all when I
save the file. I am opening the file in a "protected"
folder on the network and, I want it to be saved in its
original location. The users of my program will have the
proper priveledges on that folder, but, for those users
that don't, I do indeed want to use some error checking to
display the message.

In all of my testing, I never got an error. In those
cases when I did not have "write/save" rights on a drive,
then resulting modified .xls simply saved to my My
Documents folder.

Are you saying that I should definitely specify the my
drive and folder when I save the file?

The code that I am using to open/save the file looks like
the following:

XLApp.WorkBooks.Open(ExpandUNCFileName
(flbRegisters.Items.Strings[lcv]), 0, false);
sheet := XLApp.WorkBooks[1].Worksheets[1];
MyZoom := 100;
pSetup := 'PAGE.SETUP(,,,,';
pSetup := pSetup + ',,,,,';
pSetup := pSetup + ',,,' + IntToStr(myZoom) + ',';
pSetup := pSetup + ',,,,';
pSetup := pSetup + ',,,)';
XLApp.DisplayAlerts := False;
XLApp.Workbooks.Application.ExecuteExcel4Macro(pSetup);
XLApp.Workbooks.Application.DisplayAlerts := False;
XLApp.ActiveWorkbook.Save;
XLApp.WorkBooks.Close;

Thanks again,
Everett
-----Original Message-----
Are you sure you're specifying the correct drive and folder? I've never seen
excel just change to a different when I specify where I want it saved.

Maybe you could toss in some error checking:

Option Explicit
Sub testme()

Dim mySaved As Boolean

mySaved = ActiveWorkbook.Saved
ActiveWorkbook.Saved = False 'make it dirty

On Error Resume Next
ActiveWorkbook.SaveAs "C:\my documents\excel\book1.xls"
On Error GoTo 0

If ActiveWorkbook.Saved Then
'it did it ok
Else
MsgBox "couldn't save workbook"
ActiveWorkbook.Saved = mySaved 'put it back to what it was
End If

End Sub

You could even look at:

if err.number <> 0 then

to see if the saveas succeeded.





--

Dave Peterson
(e-mail address removed)
.
 
Dave:

I am indeed supporting multiple versions. I did not have
a "SaveAs" in my original post. When someone (me) opens
the workbook, without update capability, I do see a
[ReadOnly] in the title bar. This is in spite of the fact
that in the properties for the file, READONLY is NOT
checked. I am assuming this is the network permissions at
work. As a test, I tried to change the property and I got
an "Access Denied" error message. My guess is that with
network folder access, I would not be having these issues.

I was able to interpret teh "readonly" property of the
worksheet successfully.

At this point, I guess I am just going to have to work
with our Net Admin guys to be sure that the "proper" users
get the "proper" access.

Thanks again,
Everett
-----Original Message-----
With some versions of excel, File|saveAs will go to the same folder as the
original workbook.

With earlier versions (xl97, if I remember correctly), will go back to the
user's default folder.

It kind of sounds like you're supporting multiple versions. I think I'd make
sure I specified the intended folder:

dim myPath as string
dim wkbk as workbook
set wkbk = workbooks.open(filename:=....,etc)
on error resume next
wkbk.saveas filename:=wkbk.path & "\" & "someothername.xls"
'rest of error stuff.

But if you're really just opening, fixing and closing, you can just do a

wkbk.save
(wrapped nicely with error checking.)

====
Did I read an invisible File|SaveAs into your first message? It seems to have
disappeared when I reread it!

======

When someone opens that workbook without update capability, do they see
[ReadOnly] in the workbook's title bar?

That's the way I remember it working for me when I can't update a file. Excel
respects those windows/OS settings.

Maybe you could just check the .readonly property.

If ActiveWorkbook.ReadOnly Then
'don't do it
Else
ActiveWorkbook.Save
End If



Good Afternoon Dave and Thanks for your reply!

I am not specifying the drive and folder at all when I
save the file. I am opening the file in a "protected"
folder on the network and, I want it to be saved in its
original location. The users of my program will have the
proper priveledges on that folder, but, for those users
that don't, I do indeed want to use some error checking to
display the message.

In all of my testing, I never got an error. In those
cases when I did not have "write/save" rights on a drive,
then resulting modified .xls simply saved to my My
Documents folder.

Are you saying that I should definitely specify the my
drive and folder when I save the file?

The code that I am using to open/save the file looks like
the following:

XLApp.WorkBooks.Open(ExpandUNCFileName
(flbRegisters.Items.Strings[lcv]), 0, false);
sheet := XLApp.WorkBooks[1].Worksheets[1];
MyZoom := 100;
pSetup := 'PAGE.SETUP(,,,,';
pSetup := pSetup + ',,,,,';
pSetup := pSetup + ',,,' + IntToStr(myZoom) + ',';
pSetup := pSetup + ',,,,';
pSetup := pSetup + ',,,)';
XLApp.DisplayAlerts := False;
XLApp.Workbooks.Application.ExecuteExcel4Macro(pSetup);
XLApp.Workbooks.Application.DisplayAlerts := False;
XLApp.ActiveWorkbook.Save;
XLApp.WorkBooks.Close;

Thanks again,
Everett
-----Original Message-----
Are you sure you're specifying the correct drive and folder? I've never seen
excel just change to a different when I specify where I want it saved.

Maybe you could toss in some error checking:

Option Explicit
Sub testme()

Dim mySaved As Boolean

mySaved = ActiveWorkbook.Saved
ActiveWorkbook.Saved = False 'make it dirty

On Error Resume Next
ActiveWorkbook.SaveAs "C:\my documents\excel\book1.xls"
On Error GoTo 0

If ActiveWorkbook.Saved Then
'it did it ok
Else
MsgBox "couldn't save workbook"
ActiveWorkbook.Saved = mySaved 'put it back to what it was
End If

End Sub

You could even look at:

if err.number <> 0 then

to see if the saveas succeeded.




Everett wrote:

Hello All!

I am using Excel 2000 and I have a question.

I have a program (Delphi) which makes a call that executes
an excel macro. The macro does nothing more than change
the value of the "zooming/scaling" value from
whatever
it
is to 100%. For some users, who don't have WRITE/SAVE
access to the directory where the .xls files live, the
newly modified .xls file gets saved into the "My
Documents" folder instead of the network drive where
the .xls originally was opened. My question is, is there
a way to determine if a user has the "proper rights" for
the original folder where the .xls resides?

I want to be able to throw up a warning message in those
cases where the user does not have "write/save" right for
the directory where the .xls is located.

Thanks in advance for all suggestions and replies!

Everett

--

Dave Peterson
(e-mail address removed)
.

--

Dave Peterson
(e-mail address removed)
.
 
From what I can see, excel will show readonly in the titlebar if:

1. You saved it with a write reservation password and the user opened the file
in readonly mode.

2. You set the readonly property of the file to readonly. (in Windows
explorer|rightclick|properties|General Tab|check readonly.

3. You don't have write access to that sharename.

(I'm not sure all network operating systems support this. (I've never used
Novell and lots of others).)

(sorry about the SaveAs stuff.)


Dave:

I am indeed supporting multiple versions. I did not have
a "SaveAs" in my original post. When someone (me) opens
the workbook, without update capability, I do see a
[ReadOnly] in the title bar. This is in spite of the fact
that in the properties for the file, READONLY is NOT
checked. I am assuming this is the network permissions at
work. As a test, I tried to change the property and I got
an "Access Denied" error message. My guess is that with
network folder access, I would not be having these issues.

I was able to interpret teh "readonly" property of the
worksheet successfully.

At this point, I guess I am just going to have to work
with our Net Admin guys to be sure that the "proper" users
get the "proper" access.

Thanks again,
Everett
-----Original Message-----
With some versions of excel, File|saveAs will go to the same folder as the
original workbook.

With earlier versions (xl97, if I remember correctly), will go back to the
user's default folder.

It kind of sounds like you're supporting multiple versions. I think I'd make
sure I specified the intended folder:

dim myPath as string
dim wkbk as workbook
set wkbk = workbooks.open(filename:=....,etc)
on error resume next
wkbk.saveas filename:=wkbk.path & "\" & "someothername.xls"
'rest of error stuff.

But if you're really just opening, fixing and closing, you can just do a

wkbk.save
(wrapped nicely with error checking.)

====
Did I read an invisible File|SaveAs into your first message? It seems to have
disappeared when I reread it!

======

When someone opens that workbook without update capability, do they see
[ReadOnly] in the workbook's title bar?

That's the way I remember it working for me when I can't update a file. Excel
respects those windows/OS settings.

Maybe you could just check the .readonly property.

If ActiveWorkbook.ReadOnly Then
'don't do it
Else
ActiveWorkbook.Save
End If



Good Afternoon Dave and Thanks for your reply!

I am not specifying the drive and folder at all when I
save the file. I am opening the file in a "protected"
folder on the network and, I want it to be saved in its
original location. The users of my program will have the
proper priveledges on that folder, but, for those users
that don't, I do indeed want to use some error checking to
display the message.

In all of my testing, I never got an error. In those
cases when I did not have "write/save" rights on a drive,
then resulting modified .xls simply saved to my My
Documents folder.

Are you saying that I should definitely specify the my
drive and folder when I save the file?

The code that I am using to open/save the file looks like
the following:

XLApp.WorkBooks.Open(ExpandUNCFileName
(flbRegisters.Items.Strings[lcv]), 0, false);
sheet := XLApp.WorkBooks[1].Worksheets[1];
MyZoom := 100;
pSetup := 'PAGE.SETUP(,,,,';
pSetup := pSetup + ',,,,,';
pSetup := pSetup + ',,,' + IntToStr(myZoom) + ',';
pSetup := pSetup + ',,,,';
pSetup := pSetup + ',,,)';
XLApp.DisplayAlerts := False;
XLApp.Workbooks.Application.ExecuteExcel4Macro(pSetup);
XLApp.Workbooks.Application.DisplayAlerts := False;
XLApp.ActiveWorkbook.Save;
XLApp.WorkBooks.Close;

Thanks again,
Everett
-----Original Message-----
Are you sure you're specifying the correct drive and
folder? I've never seen
excel just change to a different when I specify where I
want it saved.

Maybe you could toss in some error checking:

Option Explicit
Sub testme()

Dim mySaved As Boolean

mySaved = ActiveWorkbook.Saved
ActiveWorkbook.Saved = False 'make it dirty

On Error Resume Next
ActiveWorkbook.SaveAs "C:\my
documents\excel\book1.xls"
On Error GoTo 0

If ActiveWorkbook.Saved Then
'it did it ok
Else
MsgBox "couldn't save workbook"
ActiveWorkbook.Saved = mySaved 'put it back to
what it was
End If

End Sub

You could even look at:

if err.number <> 0 then

to see if the saveas succeeded.




Everett wrote:

Hello All!

I am using Excel 2000 and I have a question.

I have a program (Delphi) which makes a call that
executes
an excel macro. The macro does nothing more than change
the value of the "zooming/scaling" value from whatever
it
is to 100%. For some users, who don't have WRITE/SAVE
access to the directory where the .xls files live, the
newly modified .xls file gets saved into the "My
Documents" folder instead of the network drive where
the .xls originally was opened. My question is, is
there
a way to determine if a user has the "proper rights" for
the original folder where the .xls resides?

I want to be able to throw up a warning message in those
cases where the user does not have "write/save" right
for
the directory where the .xls is located.

Thanks in advance for all suggestions and replies!

Everett

--

Dave Peterson
(e-mail address removed)
.

--

Dave Peterson
(e-mail address removed)
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top