我想获得目前打开的这个excel文件是不是只读的,如果是,不保存。如果不是只读的,就保存。
我用: a=GetAttr("book1.xls")
If a = 1 Then
Workbooks("book1.xls").Close Closechanges:=False
End If可是,无论是不是只读的, a 得到的值都是33 , 请问哪位前辈能给出正确的代码?谢谢啦。 在线急等。
我用: a=GetAttr("book1.xls")
If a = 1 Then
Workbooks("book1.xls").Close Closechanges:=False
End If可是,无论是不是只读的, a 得到的值都是33 , 请问哪位前辈能给出正确的代码?谢谢啦。 在线急等。
http://www.morecode.net/soft/html/19787.shtml
最后记得把新写上去的东西删除~
VB文件属性
0 一般
1 只读
2 隐藏
4 系统
16 文件夹
32 保存属性
这些数值可以综合运用,当一个文件只读且又是保存属性,则属性代码为 1 + 32 = 33。
隐藏文件夹的属性代号 2 + 16 = 18。
●GetAttr。
得知文件的属性: Private Sub Command1_Click()
Print GetAttr("C:\Autoexec.Bat")
If GetAttr("C:\Autoexec.Bat") And 1 Then Print "此文件只读"
If GetAttr("C:\Autoexec.Bat") And 2 Then Print "此文件隐藏"
If GetAttr("C:\Autoexec.Bat") And 4 Then Print "此文件为系统文件"
If GetAttr("C:\Autoexec.Bat") And 16 Then Print "此文件为文件夹"
If GetAttr("C:\Autoexec.Bat") And 32 Then Print "此文件为保存属性"
End Sub ●SetAttr。
设定文件的属性: Private Sub Command1_Click()
SetAttr "C:\Autoexec.Bat", 1 + 2 + 32
Print "C:\Autoexec.Bat 此文件被设定成 只读 & 隐藏 & 保存属性"
End Sub
Workbooks("book1.xls").ReadOnlyTrue 表示只读。