Solved

Insert signature to email via visual basic for application

Posted on 2006-06-20
13
274 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sorting multiple rows and columns, and count duplicates in Excel 2013 4 79
Visual Studio 2005 text editor 10 38
Authentication of Web Services 3 74
Advice in Xamarin 21 79
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…
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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