Forums Neueste Beiträge
 

Start macro creating a mail with contact data and autotext

24/02/2009 - 15:18 von WaWa | Report spam
Hallo,



I am working with an user form.

The developing of that form started with Outlook XP with a lot of code
inside for different buttons.



I changed to Outlook 2007 and unfortunately the code of the form was not
longer displayed.



What I learned about this is that MS does not support to much code in the
form (or maybe a bug).

They also do not support any longer.

I was sending this form to MS support but they told it is do much code
inside and they do not know, why the code is not displayed.



In Outlook 2003 the code is displayed as in Outlook XP.



Because I do not know really how to program a user form (I put it together
with some codes I found in Internet and with the help of Newsgroups) I
thought maybe the code is the reason why it is no longer displayed in
Outlook 2007.



So I started to develop the form from beginning in Outlook 2007.



Everything worked fine, but when it comes to too much code for the 12
buttons the same thing (code is no longer displayed) happened.



I could not find out if the reason is the number of lines or characters, in
fact if I put more code inside (more lines than 140) it is not displayed.



Concerning the above I have the following questions:





1. Is there another possibility to display and edit the code I only
know the steps - develop a form, -display code.



2. If not there is the idea to write in the code ...



and start a macro instead of writing the code in the form.
Therefore I created a macro called "Mail1", is placed in Modul1, with the
following content:
Sub Mail1()



Dim Nachricht

Dim Adresse

Dim Text

Set Nachricht = Application.CreateItem(olMailItem)

Set Item = ActiveInspector.CurrentItem

Nachricht.Subject = "Subject"

Nachricht.To = Item.Email1Address

Adresse = Item.CompanyName + vbCr

Adresse = Adresse + Item.BusinessAddressStreet + vbCr

Adresse = Adresse + Item.BusinessAddressPostalCode + " "

Adresse = Adresse + Item.BusinessAddressCity + vbCr + vbCr

Adresse = Adresse + Item.Title + " " + Item.LastName + vbCr + vbCr

Nachricht.Body = Adresse



Nachricht.Categories = "Geschàftlich"

Nachricht.Importance = olImportanceNormal

'Nachricht.Send

Nachricht.Display

End Sub




With a button called .
Sub CommandButton1_Click

Application.Mail1()

End Sub

'

Private Sub CommandButton2_Click

Mail1

End Sub

'

Private Sub CommandButton3_Click

Mail1()

End Sub

'

Private Sub CommandButton4_Click

call Mail1()

End Sub

'

Private Sub CommandButton5_Click

call Mail1

End Sub

'

Private Sub CommandButton6_Click

run Mail1

End Sub

'

Sub CommandButton7_Click

Application.Mail1

End Sub

'


I try to start this macro, without success.
If I open a contact with my form a call the macro with Outlook commands, the
macro is working.



Please can anyone tell me how to call the macro and where the macro should
be placed?

Modul1,

This Outlook session?

Sub?

Private Sub?

Function?



3. The macro is creating a new email, fills in the contacts email
address and in the body the contact data.



Now I want to fill in an autotext below the address data.



I think that could be done in reading the autotext in a variable and put it
in the body like body = body + variable.



I do not want to create a menu entry or buttons in the toolbar and not only
open a mail item and choose the autotext entries from the menu.



It would be great if anybody can help me to make my button in the form alive
to call the macro.



WaWa



p.s. Windows Vista with all Windows updates, Outlook 2007 with all Office
updates. Macro security set to NO. I am not sure whether all necessary
libraries are enabled. It is a standard office installation.
 

Lesen sie die antworten

#1 Ken Slovak - [MVP - Outlook]
24/02/2009 - 16:28 | Warnen spam
The macro code has this, a reason it works only when an item is already
open:

Set Nachricht = Application.CreateItem(olMailItem)
Set Item = ActiveInspector.CurrentItem

Before the second line you should have this:

Set Nachricht = Application.CreateItem(olMailItem)

Dim oInsp As Outlook.Inspector
Set oInsp = Nachricht.GetInspector
oInsp.Display False

Set Item = ActiveInspector.CurrentItem

That gets an Inspector and shows it so ActiveInspector is valid.

Although not supported, you put a macro as a Public Sub in
ThisOutlookSession to be able to call it as Application.MySub().

I don't know about 140 lines of form code being too much, I have forms with
over 1000 lines of code in them that were designed in Outlook 2003 or
earlier that work just fine with Outlook 2007, although of course the form
must be published to have any code in it actually run.

What you really have to look out for is using too many controls on a custom
form, things start to get weird when the controls number over 130 or so.

BTW, a more targeted group of newsgroups would be better to post in.

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"WaWa" wrote in message
news:%
Hallo,



I am working with an user form.

The developing of that form started with Outlook XP with a lot of code
inside for different buttons.



I changed to Outlook 2007 and unfortunately the code of the form was not
longer displayed.



What I learned about this is that MS does not support to much code in the
form (or maybe a bug).

They also do not support any longer.

I was sending this form to MS support but they told it is do much code
inside and they do not know, why the code is not displayed.



In Outlook 2003 the code is displayed as in Outlook XP.



Because I do not know really how to program a user form (I put it together
with some codes I found in Internet and with the help of Newsgroups) I
thought maybe the code is the reason why it is no longer displayed in
Outlook 2007.



So I started to develop the form from beginning in Outlook 2007.



Everything worked fine, but when it comes to too much code for the 12
buttons the same thing (code is no longer displayed) happened.



I could not find out if the reason is the number of lines or characters,
in fact if I put more code inside (more lines than 140) it is not
displayed.



Concerning the above I have the following questions:





1. Is there another possibility to display and edit the code I only
know the steps - develop a form, -display code.



2. If not there is the idea to write in the code ...



and start a macro instead of writing the code in the form.
Therefore I created a macro called "Mail1", is placed in Modul1, with the
following content:
Sub Mail1()



Dim Nachricht

Dim Adresse

Dim Text

Set Nachricht = Application.CreateItem(olMailItem)

Set Item = ActiveInspector.CurrentItem

Nachricht.Subject = "Subject"

Nachricht.To = Item.Email1Address

Adresse = Item.CompanyName + vbCr

Adresse = Adresse + Item.BusinessAddressStreet + vbCr

Adresse = Adresse + Item.BusinessAddressPostalCode + " "

Adresse = Adresse + Item.BusinessAddressCity + vbCr + vbCr

Adresse = Adresse + Item.Title + " " + Item.LastName + vbCr + vbCr

Nachricht.Body = Adresse



Nachricht.Categories = "Geschàftlich"

Nachricht.Importance = olImportanceNormal

'Nachricht.Send

Nachricht.Display

End Sub




With a button called .
Sub CommandButton1_Click

Application.Mail1()

End Sub

'

Private Sub CommandButton2_Click

Mail1

End Sub

'

Private Sub CommandButton3_Click

Mail1()

End Sub

'

Private Sub CommandButton4_Click

call Mail1()

End Sub

'

Private Sub CommandButton5_Click

call Mail1

End Sub

'

Private Sub CommandButton6_Click

run Mail1

End Sub

'

Sub CommandButton7_Click

Application.Mail1

End Sub

'


I try to start this macro, without success.
If I open a contact with my form a call the macro with Outlook commands,
the macro is working.



Please can anyone tell me how to call the macro and where the macro should
be placed?

Modul1,

This Outlook session?

Sub?

Private Sub?

Function?



3. The macro is creating a new email, fills in the contacts email
address and in the body the contact data.



Now I want to fill in an autotext below the address data.



I think that could be done in reading the autotext in a variable and put
it in the body like body = body + variable.



I do not want to create a menu entry or buttons in the toolbar and not
only open a mail item and choose the autotext entries from the menu.



It would be great if anybody can help me to make my button in the form
alive to call the macro.



WaWa



p.s. Windows Vista with all Windows updates, Outlook 2007 with all Office
updates. Macro security set to NO. I am not sure whether all necessary
libraries are enabled. It is a standard office installation.














Ähnliche fragen