![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi all-
I am running Outlook 2003 on a WINXP machine, I am trying to add a groupreply address to the "Have replies sent to" option. JP was able to assist me with getting that part to work for a new message, but when the user has an existing email open and wants to add this, I would like for them to be able to click a button and the email address is added. I have used the sendkeys function and know that is not the best option. Here is my code I have now: Sub ExGroup_Reply_PW() '## adds group reply info only Dim objMail As Outlook.MailItem Dim myOlApp As Outlook.Application Set myOlApp = CreateObject("outlook.application") Set objMail = myOlApp.ActiveInspector.CurrentItem With objMail .ReplyRecipients.Add " End With End Sub It works, but I get the message that Sue speaks of at: http://outlookcode.com/article.aspx?id=52 I could really use some help with supressing or not getting this warning. Also, we have used this code to open the saveas option and choose the outlook .msg as the save type: sendkeys "%fa%too{tab}" I would love to use better VBA coding to get this done. |
Ads |
#2
|
|||
|
|||
![]()
If this VBA code is running in Outlook VBA do not use CreateObject() to get
your Outlook.Application object, that won't be trusted. Use the intrinsic Application object in Outlook VBA code, that is trusted. Then derive all of your Outlook objects from the safe Application object. If this code isn't running in the Outlook VBA project then you already have the answers on how to avoid the security dialogs from the article you linked to. You can open the SaveAs dialog by using the Execute method on the File, SaveAs CommandBarButton. However once in that dialog there is no exposure to the object model. As bad as using SendKeys is there is no alternative for sending a keypress to the dialog unless you go way low level and use a post action to post a message to the SaveAs dialog window using Win32 API calls. May I ask why you are going through those hoops instead of using the SaveAs method of a MailItem and using the olMSG argument for the type of save? -- 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 "DStrong" wrote in message ... Hi all- I am running Outlook 2003 on a WINXP machine, I am trying to add a groupreply address to the "Have replies sent to" option. JP was able to assist me with getting that part to work for a new message, but when the user has an existing email open and wants to add this, I would like for them to be able to click a button and the email address is added. I have used the sendkeys function and know that is not the best option. Here is my code I have now: Sub ExGroup_Reply_PW() '## adds group reply info only Dim objMail As Outlook.MailItem Dim myOlApp As Outlook.Application Set myOlApp = CreateObject("outlook.application") Set objMail = myOlApp.ActiveInspector.CurrentItem With objMail .ReplyRecipients.Add " End With End Sub It works, but I get the message that Sue speaks of at: http://outlookcode.com/article.aspx?id=52 I could really use some help with supressing or not getting this warning. Also, we have used this code to open the saveas option and choose the outlook .msg as the save type: sendkeys "%fa%too{tab}" I would love to use better VBA coding to get this done. |
#3
|
|||
|
|||
![]()
Sorry, I am new to VBA in outlook. I have only been doing these for the past
two days now. I am experienced in VBA in excel and can do nearly anything in that. So the reason why I am doing things this way is that they are the only way I know how. To also answer the Saveas question, we need open the saveas dialog box that prompts the user for the location that they want to save the file and I want to have the type defualt to and outlook .msg file type for archive purposes. Many users use the defualt .rtf format and we are trying to be consistant. I am searching the web for help and this is where I am at as of now. Thanks for your advice, though not sure how to apply it. "Ken Slovak - [MVP - Outlook]" wrote: If this VBA code is running in Outlook VBA do not use CreateObject() to get your Outlook.Application object, that won't be trusted. Use the intrinsic Application object in Outlook VBA code, that is trusted. Then derive all of your Outlook objects from the safe Application object. If this code isn't running in the Outlook VBA project then you already have the answers on how to avoid the security dialogs from the article you linked to. You can open the SaveAs dialog by using the Execute method on the File, SaveAs CommandBarButton. However once in that dialog there is no exposure to the object model. As bad as using SendKeys is there is no alternative for sending a keypress to the dialog unless you go way low level and use a post action to post a message to the SaveAs dialog window using Win32 API calls. May I ask why you are going through those hoops instead of using the SaveAs method of a MailItem and using the olMSG argument for the type of save? -- 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 "DStrong" wrote in message ... Hi all- I am running Outlook 2003 on a WINXP machine, I am trying to add a groupreply address to the "Have replies sent to" option. JP was able to assist me with getting that part to work for a new message, but when the user has an existing email open and wants to add this, I would like for them to be able to click a button and the email address is added. I have used the sendkeys function and know that is not the best option. Here is my code I have now: Sub ExGroup_Reply_PW() '## adds group reply info only Dim objMail As Outlook.MailItem Dim myOlApp As Outlook.Application Set myOlApp = CreateObject("outlook.application") Set objMail = myOlApp.ActiveInspector.CurrentItem With objMail .ReplyRecipients.Add " End With End Sub It works, but I get the message that Sue speaks of at: http://outlookcode.com/article.aspx?id=52 I could really use some help with supressing or not getting this warning. Also, we have used this code to open the saveas option and choose the outlook .msg as the save type: sendkeys "%fa%too{tab}" I would love to use better VBA coding to get this done. |
#4
|
|||
|
|||
![]()
The Application part of my advice is easy to follow, just use Application
where you now use myOlApp and get rid of that CreateObject() line. For the SaveAs, I'd probably construct my own dialog for location, possibly using the ComDlg controls if those were installed. Otherwise I'd construct a dialog from scratch or use the Win32 API calls to open the common dialog Save dialog. VBAccelerator.com has samples of directly using the Win32 API calls. -- 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 "DStrong" wrote in message ... Sorry, I am new to VBA in outlook. I have only been doing these for the past two days now. I am experienced in VBA in excel and can do nearly anything in that. So the reason why I am doing things this way is that they are the only way I know how. To also answer the Saveas question, we need open the saveas dialog box that prompts the user for the location that they want to save the file and I want to have the type defualt to and outlook .msg file type for archive purposes. Many users use the defualt .rtf format and we are trying to be consistant. I am searching the web for help and this is where I am at as of now. Thanks for your advice, though not sure how to apply it. |
#5
|
|||
|
|||
![]()
OK, Ken, I tried what you said below and have included my code as I get a new
error message now. It says "variable or block with not set" I feel like it says that I have not defined the Application line? Am I correct? my code: Sub ExGroup_Reply_PW() '## adds group reply info only Dim objMail As Outlook.MailItem Set objMail = Application.ActiveInspector.CurrentItem With objMail .ReplyRecipients.Add " End With End Sub As for the save portion, that is all greek to me. I am not sure that I would be able to deploy something like that in this work environment. I am looking for a simple solution that does not include using sendkeys or something too complex. It seems that it should be a more simple solution. My sendkeys code was one line, it works, it just turns off NUM Lock and CAPS lock when ever that code is run. "Ken Slovak - [MVP - Outlook]" wrote: The Application part of my advice is easy to follow, just use Application where you now use myOlApp and get rid of that CreateObject() line. For the SaveAs, I'd probably construct my own dialog for location, possibly using the ComDlg controls if those were installed. Otherwise I'd construct a dialog from scratch or use the Win32 API calls to open the common dialog Save dialog. VBAccelerator.com has samples of directly using the Win32 API calls. -- 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 "DStrong" wrote in message ... Sorry, I am new to VBA in outlook. I have only been doing these for the past two days now. I am experienced in VBA in excel and can do nearly anything in that. So the reason why I am doing things this way is that they are the only way I know how. To also answer the Saveas question, we need open the saveas dialog box that prompts the user for the location that they want to save the file and I want to have the type defualt to and outlook .msg file type for archive purposes. Many users use the defualt .rtf format and we are trying to be consistant. I am searching the web for help and this is where I am at as of now. Thanks for your advice, though not sure how to apply it. |
#6
|
|||
|
|||
![]()
And what line is the error on? If the code is running in the Outlook VBA
project then Application doesn't need declaration. If it's running in some other VBA project (Word, Excel, etc.) then you can't use Application, you have to declare and instantiate an Outlook.Application object. If you are happy with how things work using SendKeys then continue to do so. You had asked how to avoid using SendKeys and I provided a couple of ways of how I'd do it. If those are unsuitable for your purposes then stick to what you have. -- 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 "DStrong" wrote in message ... OK, Ken, I tried what you said below and have included my code as I get a new error message now. It says "variable or block with not set" I feel like it says that I have not defined the Application line? Am I correct? my code: Sub ExGroup_Reply_PW() '## adds group reply info only Dim objMail As Outlook.MailItem Set objMail = Application.ActiveInspector.CurrentItem With objMail .ReplyRecipients.Add " End With End Sub As for the save portion, that is all greek to me. I am not sure that I would be able to deploy something like that in this work environment. I am looking for a simple solution that does not include using sendkeys or something too complex. It seems that it should be a more simple solution. My sendkeys code was one line, it works, it just turns off NUM Lock and CAPS lock when ever that code is run. |
#7
|
|||
|
|||
![]()
This is running in ThisOutlookSession of Outlook. The error comes at the line
Set objMail = Application.ActiveInspector.CurrentItem I appreciate your advice on the saveas options for me. In your first post you asked "May I ask why you are going through those hoops instead of using the SaveAs method of a MailItem and using the olMSG argument for the type of save?" The answer would be I do not know how that is done. I am very new to VBA programming in outlook and am trying to learn as I go. I have used what worked as a temp solution which was the sendkeys function, but that function irritates the heck out of the users who use this macro. I am getting Sue's Outlook Programming book this evening from my local library so maybe I can learn some more from that. Your suggestion in you question sounds like a viable solution, I just do not know how to code that. The work environment we are in is a remote connection using a Citrix connection, and it is through this that my users need to save the emails. They have a C drive and a my documents section that they can save to, but since everyones username is different, I have not found a solution that can give me a dynamic path to a users folders. Having the open dialog box of a location the user can choose where to save the email seems like the best solution, as this lets them choose their own save location. The problem is people forget to change the file type to outlooks .msg. Does this make more sense? Much thanks! David "Ken Slovak - [MVP - Outlook]" wrote: And what line is the error on? If the code is running in the Outlook VBA project then Application doesn't need declaration. If it's running in some other VBA project (Word, Excel, etc.) then you can't use Application, you have to declare and instantiate an Outlook.Application object. If you are happy with how things work using SendKeys then continue to do so. You had asked how to avoid using SendKeys and I provided a couple of ways of how I'd do it. If those are unsuitable for your purposes then stick to what you have. -- 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 "DStrong" wrote in message ... OK, Ken, I tried what you said below and have included my code as I get a new error message now. It says "variable or block with not set" I feel like it says that I have not defined the Application line? Am I correct? my code: Sub ExGroup_Reply_PW() '## adds group reply info only Dim objMail As Outlook.MailItem Set objMail = Application.ActiveInspector.CurrentItem With objMail .ReplyRecipients.Add " End With End Sub As for the save portion, that is all greek to me. I am not sure that I would be able to deploy something like that in this work environment. I am looking for a simple solution that does not include using sendkeys or something too complex. It seems that it should be a more simple solution. My sendkeys code was one line, it works, it just turns off NUM Lock and CAPS lock when ever that code is run. |
#8
|
|||
|
|||
![]()
I can think of 2 reasons why you'd get that error in code running in
ThisOutlookSession: the object isn't a MailItem or there is no ActiveInspector (nothing open). Otherwise the line should work. As far as location to save to, I'm afraid my suggestion for finding a path such as My Documents won't thrill you either if you didn't like the code for putting up a save dialog. Here's how I would get the My Documents path for any user in VBA code: Public Const MAX_PATH As Long = 260 Public Declare Function SHGetFolderPath Lib "shfolder.dll" _ Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, _ ByVal hToken As Long, ByVal dwReserved As Long, ByVal lpszPath As String) As Long Public Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long Public Const CSIDL_PERSONAL = &H5 Public Const SHGFP_TYPE_CURRENT = &H0 Public Const S_OK = 0 Public Function GetMyDocumentsPath() As String Dim buff As String On Error Resume Next 'fill buffer with the specified folder item buff = String(MAX_PATH, Chr(0)) If SHGetFolderPath(0&, CSIDL_PERSONAL, -1, SHGFP_TYPE_CURRENT, buff) = S_OK Then GetMyDocumentsPath = Left$(buff, lstrlenW(StrPtr(buff))) Else GetMyDocumentsPath = "" End If End Function -- 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 "DStrong" wrote in message ... This is running in ThisOutlookSession of Outlook. The error comes at the line Set objMail = Application.ActiveInspector.CurrentItem I appreciate your advice on the saveas options for me. In your first post you asked "May I ask why you are going through those hoops instead of using the SaveAs method of a MailItem and using the olMSG argument for the type of save?" The answer would be I do not know how that is done. I am very new to VBA programming in outlook and am trying to learn as I go. I have used what worked as a temp solution which was the sendkeys function, but that function irritates the heck out of the users who use this macro. I am getting Sue's Outlook Programming book this evening from my local library so maybe I can learn some more from that. Your suggestion in you question sounds like a viable solution, I just do not know how to code that. The work environment we are in is a remote connection using a Citrix connection, and it is through this that my users need to save the emails. They have a C drive and a my documents section that they can save to, but since everyones username is different, I have not found a solution that can give me a dynamic path to a users folders. Having the open dialog box of a location the user can choose where to save the email seems like the best solution, as this lets them choose their own save location. The problem is people forget to change the file type to outlooks .msg. Does this make more sense? Much thanks! David |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook Security Warning | dkschoonover | Outlook and VBA | 12 | August 23rd 08 12:21 AM |
Security Warning | Loominator | Outlook Express | 2 | December 4th 07 12:12 AM |
Security warning | Christian Goeller | Outlook - General Queries | 6 | March 22nd 07 03:13 PM |
How to disable security warning? | Richard Lewis Haggard | Outlook - General Queries | 2 | April 4th 06 04:07 PM |
Internet Security Warning.... | Jeff | Outlook Express | 3 | March 29th 06 08:13 PM |