【问题标题】:With VBA, how can I check if, in Windows Explorer, the file extensions for known file types are hidden?使用 VBA,如何在 Windows 资源管理器中检查已知文件类型的文件扩展名是否隐藏?
【发布时间】:2009-07-22 11:27:24
【问题描述】:

无需打开 Windows 资源管理器。我想从 Word VBA 中检查这一点。

谢谢。

编辑:

此代码现在可以使用:

Set WshShell = CreateObject("WScript.Shell")

If WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt") = 0 Then
    MsgBox Prompt:="In Windows Explorer, set the folder options to hide file extensions of known file types." _
        & vbCrLf & vbCrLf & " This prevents the file extension from appearing as part of the document number in" _
        & "the document body and page headers.", Buttons:=vbOKOnly + vbCritical, Title:="Critical"
End If

【问题讨论】:

    标签: vba windows-explorer file-extension ms-word


    【解决方案1】:

    需要查询注册表值

    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt

    如果该值为 0,则显示扩展,如果为 1,则隐藏。

    您可以使用 WshShell 对象上的RegRead 方法来读取此值。您可以在 VBA 项目中添加对 Windows 脚本宿主对象模型类型库的引用,以便在使用 WshShell 对象时获得强类型。

    【讨论】:

    • 谢谢,Martin,但我收到“需要对象”错误。请检查我在上述问题中的代码。我已经包含了我编辑的代码。
    • 此外,当弹出错误对话框时,HKey 字符串中的“Windows”术语会突出显示。
    • 嗨 Martin,它现在可以工作了,但是您忘记在“CurrentVersion”和“Advanced”之间添加“Explorer”。
    猜你喜欢
    • 2015-03-02
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 2015-09-10
    相关资源
    最近更新 更多