Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 480
  • Last Modified:

Where do I find the signature folder from VBA

Where in the Outlook object tree do I find the folder used for signatures?
0
thor_ostergaard
Asked:
thor_ostergaard
  • 4
  • 4
1 Solution
 
bruintjeCommented:
Hello thor_ostergaard,

not sure if it is exposed in the object model but this is another way to get the path and the file
it is vb script but you can copy paste it in vba the messagebox will give you the file and path of the signature file

---------
Dim strName, strFilePath, strFileExt, strFile
Dim oFile, oFolder,dtePrevDate

---------
'this part gets the username and path to the signature file
---------

Dim WSHNetwork: Set WSHNetwork = WScript.CreateObject("WScript.Network")

strName = WSHNetwork.UserName
strFilePath = "C:\Documents and Settings\" & _
    strName & "\Application Data\Microsoft\Signatures"


---------
'this part gets the latest signature file
---------
' file extension to look for
strFileExt = "rtf"

Dim oFSO: Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strFilePath)

' get the newest signature file
dtePrevDate = "0"
For Each oFile In oFolder.Files
   If LCase(oFSO.GetExtensionName(oFile.Name)) = LCase(strFileExt) Then
     If DateDiff("s", dtePrevDate, oFile.DateLastModified) > 0 Then
       strFile = oFile.Path
       dtePrevDate = oFile.DateLastModified
     End If
   End If
Next

msgbox strFile
---------

hope this helps a bit
bruintje
0
 
thor_ostergaardAuthor Commented:
Well - i'm not sure it helps.
I know that the path "Application Data\Microsoft\Signatures" is different in different language versions of outlook so I was looking after the "real" path.
0
 
bruintjeCommented:
i can't find that info from the outlook objectmodel, otherwise if you have the filename you could look up the path from there by searching the file first in the user data folder, the signature folder is not an important default folder like the desktop or temp folders that you can get through the environment variables or fso

if you need to implement a interface for different languages then i think using a sort of case select based on the language to get the right folder is the easiest way to solve it

but maybe someone else has a better idea
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
thor_ostergaardAuthor Commented:
I found this:
----------
The name of the signatures folder is stored in the registry:
HKCU\Software\Microsoft\Office\11.0\Common\General\Signatures
----------

Don't know how to read from registry in VBA
Don't know how to determin the office version.
Don't know if this path is the same in all office versions (except for 11.0)
0
 
bruintjeCommented:
to read the key you can use

Set oShell = CreateObject("WScript.Shell")
strSigFolder = oShell.RegRead("HKCU\Software\Microsoft\Office\11.0\Common\General\Signatures")

but that gives me only a value of Signatures not a folder but i don't use them so i'm not sure how it looks if you do

The regkey is the same for me in office 9.0, 10.0 and 11.0 but couldn't find it under 8.0

how to determine the office version is a bit more difficult because a user can multiple installations, if you need to get it from the active application [i assume outlook here]

strVersion = Application.Version

0
 
thor_ostergaardAuthor Commented:
And a better way to get the username:

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function UserNameWindows() As String
   
    Dim lngLen As Long
    Dim strBuffer As String
   
    Const dhcMaxUserName = 255
   
    strBuffer = Space(dhcMaxUserName)
    lngLen = dhcMaxUserName
    If CBool(GetUserName(strBuffer, lngLen)) Then
        UserNameWindows = Left$(strBuffer, lngLen - 1)
    Else
        UserNameWindows = ""
    End If
End Function

0
 
thor_ostergaardAuthor Commented:
Thanks for your help
0
 
bruintjeCommented:
thanks for the grade, i hope you found some value in it
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now