How can I insert the default Outlook signature into a document?

C

Chris Mahoney

Hi

Each of my users has a default signature set up in Outlook. I'd like to
be able to pull this signature into a Word document. I know that there
is a link between the two apps (after all, you can use Word as your
email editor), is this link accessible from VBA or will I need to
automate Outlook in order to get the signature from it?

While looking around for a solution, I found several posts that say
that signatures are accessed two different ways depending on whether or
not WordMail is used. All of these posts are referring to the GUI. When
using VBA will I need to have two different code paths, or does VBA
always access the signature in the same way?

Thanks
Chris
 
C

Chris Mahoney

I've found a solution, for WordMail at least. There's a post here from
last year, the abominably-named "Word VBA Question" that tells me
exactly what to do :)

I have yet to try non-WordMail signatures though.
 
Z

zkid

Chris,

The signatures are located in the following folder:

C:\Documents and Settings\[UserName]\Application Data\Microsoft\Signatures

Each signature has three versions from which to choose: .rtf, .txt or
..html (txt wipes out any formatting).

Use the following code to determine the user's login name to maneuver to the
correct folder:

Option Explicit

'Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long

Const NoError = 0 'The Function call was successful

Function GetCurUser() As String

'Buffer size for the return string.
Const lpnLength As Long = 255

'Get return buffer space.
Dim status As Integer

'For getting user information.
Dim lpName, lpUserName As String

'Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

'Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)

'See whether error occurred.
If status = NoError Then
'This line removes the null character. Strings in C are null-
'terminated. Strings in Visual Basic are not null-terminated.
'The null character must be removed from the C strings to be used
'cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
End If

'Display the name of the person logged on to the machine.
GetCurUser = lpUserName

End Function
 
C

Chris Mahoney

Thanks, that's pretty much what the other code that I mentioned did.
Instead of assuming that the signatures will be on drive C: (they're
not), I'm using the APPDATA environment variable. This makes it point
to the appropriate place (U:\Settings\Application Data in my case)
without having to look up the user name :)

Chris

Chris,

The signatures are located in the following folder:

C:\Documents and Settings\[UserName]\Application Data\Microsoft\Signatures

Each signature has three versions from which to choose: .rtf, .txt or
.html (txt wipes out any formatting).

Use the following code to determine the user's login name to maneuver to the
correct folder:

Option Explicit

'Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long

Const NoError = 0 'The Function call was successful

Function GetCurUser() As String

'Buffer size for the return string.
Const lpnLength As Long = 255

'Get return buffer space.
Dim status As Integer

'For getting user information.
Dim lpName, lpUserName As String

'Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

'Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)

'See whether error occurred.
If status = NoError Then
'This line removes the null character. Strings in C are null-
'terminated. Strings in Visual Basic are not null-terminated.
'The null character must be removed from the C strings to be used
'cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
End If

'Display the name of the person logged on to the machine.
GetCurUser = lpUserName

End Function


Chris Mahoney said:
I've found a solution, for WordMail at least. There's a post here from
last year, the abominably-named "Word VBA Question" that tells me
exactly what to do :)

I have yet to try non-WordMail signatures though.
 
Z

zkid

Oh, okay. I had no idea what code you were using. However, that being said,
be careful with APPDATA. Please see this article if you start having
problems:

http://support.microsoft.com/default.aspx?scid=kb;en-us;329308&Product=winxp

The code I provided you works within Word VBA itself and has never caused me
any problems.

Chris Mahoney said:
Thanks, that's pretty much what the other code that I mentioned did.
Instead of assuming that the signatures will be on drive C: (they're
not), I'm using the APPDATA environment variable. This makes it point
to the appropriate place (U:\Settings\Application Data in my case)
without having to look up the user name :)

Chris

Chris,

The signatures are located in the following folder:

C:\Documents and Settings\[UserName]\Application Data\Microsoft\Signatures

Each signature has three versions from which to choose: .rtf, .txt or
.html (txt wipes out any formatting).

Use the following code to determine the user's login name to maneuver to the
correct folder:

Option Explicit

'Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long

Const NoError = 0 'The Function call was successful

Function GetCurUser() As String

'Buffer size for the return string.
Const lpnLength As Long = 255

'Get return buffer space.
Dim status As Integer

'For getting user information.
Dim lpName, lpUserName As String

'Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

'Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)

'See whether error occurred.
If status = NoError Then
'This line removes the null character. Strings in C are null-
'terminated. Strings in Visual Basic are not null-terminated.
'The null character must be removed from the C strings to be used
'cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
End If

'Display the name of the person logged on to the machine.
GetCurUser = lpUserName

End Function


Chris Mahoney said:
I've found a solution, for WordMail at least. There's a post here from
last year, the abominably-named "Word VBA Question" that tells me
exactly what to do :)

I have yet to try non-WordMail signatures though.
 
C

Chris Mahoney

Oh, okay. I had no idea what code you were using.

Yeah, that was my fault, I should've actually posted the code I was
using instead of expecting you to find it yourself :)
However, that being said,
be careful with APPDATA. Please see this article if you start having
problems:

http://support.microsoft.com/default.aspx?scid=kb;en-us;329308&Product=winxp

I'll keep that in mind, but hopefully it won't be a problem.
The code I provided you works within Word VBA itself and has never caused me
any problems.

Just to complicate things :) I know I said I was using VBA, but I've
switched over to .NET now, I decided it'd be easier in the long run. I
can therefore use System.Environment.UserName without having to call
APIs.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top