如何使用 vba 更改扩展文件属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16989882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I change extended file properties using vba
提问by Ben
Using this linkI was able to write a program in vba that reads extended file properties. Now, I'd like to make a program that can edit extended file properties - specifically property 22, the "subject" of a file. So, given a file path, how could you edit the subject associated with that file?
使用此链接,我能够在 vba 中编写一个读取扩展文件属性的程序。现在,我想制作一个可以编辑扩展文件属性的程序——特别是属性 22,文件的“主题”。那么,给定一个文件路径,您如何编辑与该文件关联的主题?
回答by jac
It can't be done using the method you are using now. You can install and use the Microsoft ActiveX dsofile.dllto both get and set extended properties using VBScript.
使用您现在使用的方法无法完成。您可以安装和使用 Microsoft ActiveX dsofile.dll来使用 VBScript 获取和设置扩展属性。
Set objFile = CreateObject("DSOFile.OleDocumentProperties")
objFile.Open("C:\My Path\MyFile.doc")
objFile.SummaryProperties.Subject = "My Subject"
objFile.Save
set objFile = Nothing
回答by awsmitty
This is really more of a comment to jac above. The .dll file referenced won't work on 64 bit machines, and I feel most machines today are 64 bit. Click Herefor an open source 64 bit equivalent to the referenced dsofile.dll.
这实际上更像是对上面 jac 的评论。引用的 .dll 文件在 64 位机器上不起作用,我觉得今天的大多数机器都是 64 位的。单击此处获取与引用的 dsofile.dll 等效的开源 64 位。
回答by Adarsh Madrecha
' Make the file Read-Only
' 使文件只读
SetAttr "c:\temp\Sample.txt", vbReadOnly
' Make the file Hidden
' 隐藏文件
SetAttr "c:\temp\Sample.txt", vbHidden
' Please note that if you change one attribute, the existing attribute is overwritten. For making a file as both readonly and hidden use both attributes in the function
' 请注意,如果您更改一个属性,则现有属性将被覆盖。要使文件既只读又隐藏,请在函数中使用这两个属性
SetAttr "c:\temp\Sample.txt", vbHidden + vbReadOnly
' Remove all atributes - convert a read-only file to read-write file, unhide the file etc
' 删除所有属性 - 将只读文件转换为读写文件,取消隐藏文件等
SetAttr "c:\temp\Sample.txt", vbNormal