Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert signature to email via visual basic for application

Posted on 2006-06-20
13
Medium Priority
?
282 Views
Last Modified: 2013-11-25
I like to insert a signature (name, telefon, ... not signature like certifcate) in a email via visual basic for application
0
Comment
Question by:ibeling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
13 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16943530
If you are sending through another email client, Only the email client can define a reoccuring signature. If you wish to add a signature, than you must concatonate whatever the signature is supposet to be to the end of the message. So;

message As String
signature As String
message = message & vbNewLine & vbNewLine & signature
0
 
LVL 10

Expert Comment

by:cool12399
ID: 16944648
are you actually writing an e-mail application? or you mean just appending a signature?
if the latter, yes, simply take your message, append the signature, and then pass the new
message to your procedure.
0
 

Author Comment

by:ibeling
ID: 16949007
I have already some signature defined in Outlook. (ones for internal use, ones for external, ones for private). So maybe my question should be more "how can i access the signature collection" ...
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 20

Expert Comment

by:alainbryden
ID: 16951584
No. The way outlook inserts a signature is to take the stored signature and code it directly into the html of the email, so the only way you can insert the signature is to do the same. There is no field such as OutlookApp.signature("Name") or anything like that that you can use.

As for where outlook stores it, all signatures are stored in HTML, Rich Text AND .txt format under

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

So if you know the name of the signature. You can concatonate as follows.

Open up C:\Documents and Settings\[username]\Application Data\Microsoft\Signatures\myName.txt (or .htm or .rtf )
Copy Everything
Paste it into your message.
This can easily be automated, let me know if you can't figure it out.
0
 

Author Comment

by:ibeling
ID: 16951637
It will help me to save time if you can make a little code snippet, to start.

Thanks
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 16951745
Well I have no idea how you're writing you email in Visual basic, but to access that file you say:

dim SIGNATURE As String, text As String, _
       SignatureName As String, Username As String
username =  'Fill this in yourself
SignatureName =  Name 'Fill this in yourself

Open "C:\Documents and Settings\" & Username & "\Application Data\Microsoft\Signatures\" & SignatureName & ".txt" For Input As #1

SIGNATURE = vbNullString
Do While Not EOF(1)
    Line Input #1, text
    SIGNATIRE = SIGNATURE & vbNewLine & text
Loop
Close #1   'Closes the signature file you opened

'At this point you have the entire signature stored as a string (SIGNATURE). Do with it what you will. Attatch it to the end of the message is probably the best thing.

MessageTextBox.text = MessageTextBox.text & vbNewLine & SIGNATURE

'Now send the message, complete with signature and all.
0
 
LVL 10

Expert Comment

by:cool12399
ID: 16953606
If you need outlook code, take a look here:
http://www.outlookcode.com/
0
 

Author Comment

by:ibeling
ID: 16953755
We generate Emails from a application.
Depend of the system variable USERNAME, we want add his signature.
Yes it is strange. But the customer wishes are our job.
Thanks for help.

Regards Ingo
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 2000 total points
ID: 16953996
Well ibeling, according to your description the solution is this:

dim SIGNATURE As String, text As String, _
       SignatureName As String, Username As String

SignatureName = 'SEE BELOW

Open "C:\Documents and Settings\" & USERNAME & "\Application Data\Microsoft\Signatures\" & SignatureName & ".txt" For Input As #1

SIGNATURE = vbNullString
Do While Not EOF(1)
    Line Input #1, text
    SIGNATIRE = SIGNATURE & vbNewLine & text
Loop
Close #1   'Closes the signature file you opened

'Attatch the signature


What that code will do is locate the signature, and copy it to that string SIGNATURE, then you need to take that string and append it to the end of the email message. I know you can do that on your own.


The only problem now is how do you get the SignatureName? This is almost always called "Name.txt" But the user is able to rename his signatures and have more than one. The only solution is to let the user browse and select a user name. Do to that you need to add In Project components the Windows Common Dialog Control, and drag one onto your form, and name it "FileDialog".

Once you do this add these lines of code before my code:

   Dim SignatureLocation

    FileDialog.DialogTitle = "Load A Signature"
    FileDialog.DefaultExt = "txt"
    FileDialog.Filter = "Text Documents (*.txt)|*.txt"
    FileDialog.Flags = &H1004 ' This flag means only existing names are allowed and no read-only
    FileDialog.InitDir = "C:\Documents and Settings\" & Username & "\Application Data\Microsoft\Signatures\"
    FileDialog.ShowOpen     'User selects the file to open

    Open FileDialog.FileName For Input As #1

And then the rest of the code is the same and you will have their signature. Try it out. You will see it works 100%. I already tested it myself. If you want, you can store this signature so that they only have to load it once and then it always uses the same signature again. I'm sure you can handle this much.


Enjoy.
0
 
LVL 20

Expert Comment

by:alainbryden
ID: 17293295
once taking reccomendations, if a response isn't given, I would like to suggest that I gave a working solution.

Alain
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question