views:

284

answers:

1

Without opening Windows Explorer. I want to check for this from Word VBA.

Thanks.

EDIT:

This code works now:

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
+4  A: 

You need to query the registry value

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

Extensions are shown if this value is 0 and hidden if it is 1.

You can use the RegRead method on the WshShell object to read this value. You can add an reference to the Windows Script Host Object Model type library in your VBA project to get strong typing when you use the WshShell object.

Martin Liversage
Thanks, Martin, but I get an "Object required" error. Please check my code in the question above. I have included my edited code.
Geoffrey Van Wyk
Also, the "Windows" term in the HKey string is higlighted when the error dialog pops up.
Geoffrey Van Wyk
Hi Martin, it works now, but you forgot to include "Explorer" between "CurrentVersion" and "Advanced".
Geoffrey Van Wyk
Sorry about that. I have corrected my answer.
Martin Liversage