Solved

Insert signature to email via visual basic for application

Posted on 2006-06-20
13
281 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 11 hours left to enroll

627 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