Re: SetAttr() Behaves differently under Vista
- From: "Karl E. Peterson" <karl@xxxxxxxx>
- Date: Tue, 8 May 2007 11:08:40 -0700
news-server.socal.rr.com <allen@xxxxxxxxxxxxxxxxx> wrote:
I'm trying to set a files attributes to NOT (Read Only) like so:
SetAttr sFile, GetAttr(sFile) And (Not vbReadOnly)
When the line above is called, I get a "Run-time error '5': Invalid
procedure call or argument"
GetAttr(sFile) = 8224
vbReadOnly = 1
The same run time error occurs if I simply call:
SetAttr sFile, GetAttr(sFile)
Is there some compatibilty issue I should know about between Vista and older
OS's?????
It's not just Vista. SetAttr just doesn't accept the higher-bit attributes. See
this post from 2003:
http://groups.google.com/group/microsoft.public.office.developer.vba/browse_thread/thread/f6a17d421f8af449/a52af5c17cb2fc94?lnk=st&q=&rnum=1#a52af5c17cb2fc94
In a nutshell, you need to use the API instead. Override the native SetAttr with
one of your own:
Private Declare Function SetFileAttributes Lib "kernel32" Alias
"SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As
Long
Public Function SetAttr(FileName As String, ByVal Attributes As Long) As Boolean
' Nothing fancy, just set new attribute and return
SetAttr = SetFileAttributes(FileName, Attributes)
End Function
--
..NET: It's About Trust!
http://vfred.mvps.org
.
- References:
- SetAttr() Behaves differently under Vista
- From: news-server.socal.rr.com
- SetAttr() Behaves differently under Vista
- Prev by Date: Re: Menus Question
- Next by Date: Re: Installing MS Java VM for VS6 Pro destroyed Windows 2000
- Previous by thread: SetAttr() Behaves differently under Vista
- Index(es):
Relevant Pages
|