|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Start macro creating a mail with contact data and autotextI 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. 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. -- Show quoteHide quoteKen 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" <an***@gmx.net> wrote in message news:%23TOAw4olJHA.4252@TK2MSFTNGP02.phx.gbl... > 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. > > > > > > > > > > > > > > Dear Ken,
thank you for your help but I have still problems calling the macro. In "ThisOutlookSession" I have the following: Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) End Sub I do not know where this 2 lines above came from Private Sub Mail1() Dim Nachricht Dim Adresse Dim Text Set Nachricht = Application.CreateItem(olMailItem) Dim oInsp As Outlook.Inspector Set oInsp = Nachricht.GetInspector oInsp.Display False 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.Display End Sub In the form code I have the following: Sub CommandButton1_Click Application.Mail1() End Sub to open the macro with the commandbutton. Also Private Sub CommandButton1_Click Application.Mail1() End Sub Does not work Macro security is set to no. If I push the button I got the following message "The object does not support feature ore method: Application.Mail1" I hope you can tell me the right code or are there some other outlook settings to be set to make it work. Thanks a lot WaWa ---------------------------- Show quoteHide quote "Ken Slovak - [MVP - Outlook]" <kenslo***@mvps.org> schrieb im Newsbeitrag news:O8eN8SplJHA.4372@TK2MSFTNGP02.phx.gbl... > 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" <an***@gmx.net> wrote in message > news:%23TOAw4olJHA.4252@TK2MSFTNGP02.phx.gbl... >> 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. >> >> >> >> >> >> >> >> >> >> >> >> >> >> > Re-read what I said:
"Although not supported, you put a macro as a Public Sub..." You made the Sub Private in scope. -- Show quoteHide quoteKen 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" <an***@gmx.net> wrote in message news:%23bDZRwNmJHA.4128@TK2MSFTNGP02.phx.gbl... > Dear Ken, > thank you for your help but I have still problems calling the macro. > > In "ThisOutlookSession" I have the following: > > Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) > End Sub > > I do not know where this 2 lines above came from > > Private Sub Mail1() > > Dim Nachricht > Dim Adresse > Dim Text > Set Nachricht = Application.CreateItem(olMailItem) > Dim oInsp As Outlook.Inspector > Set oInsp = Nachricht.GetInspector > oInsp.Display False > 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.Display > End Sub > > In the form code I have the following: > Sub CommandButton1_Click > > Application.Mail1() > > End Sub > > > to open the macro with the commandbutton. > Also > Private Sub CommandButton1_Click > > Application.Mail1() > > End Sub > > Does not work > > Macro security is set to no. > If I push the button I got the following message "The object does not > support feature ore method: Application.Mail1" > > I hope you can tell me the right code or are there some other outlook > settings to be set to make it work. > > Thanks a lot > WaWa
Other interesting topics
Working with Outlook Contacts from Access
Delegate Exporting Contacts using VBA? avoid syncing birthday date to calendar when saving contact Item Outlook confirmation dialog. Add internet header in Outgoing email? Sample Code Show Sender Address in Tooltip or Customized View Redemption Error code 13 while opening addressbook - vbscript Walking the Inbox Error 2711.An internal error has occurred. (OutlookCDO) Custom Pane/Custom Interface |
|||||||||||||||||||||||