Avec VBA, comment puis-je vérifier si, dans l'Explorateur Windows, les extensions de fichier pour les types de fichiers connus sont cachés?

StackOverflow https://stackoverflow.com/questions/1164626

Question

Sans ouvrir l'Explorateur Windows. Je veux vérifier cela à partir de Word VBA.

Merci.

EDIT:

Ce code fonctionne maintenant:

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
Était-ce utile?

La solution

Vous devez interroger la valeur de Registre

  

HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Avancé \ HideFileExt

Les extensions sont montrées si cette valeur est 0 et caché si elle est 1.

Vous pouvez utiliser la méthode RegRead sur l'objet WshShell à lire cette valeur. Vous pouvez ajouter une référence à la bibliothèque de type Object Model Windows Script Host dans votre projet VBA pour obtenir un typage fort lorsque vous utilisez l'objet WshShell.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top