Quantcast
Channel: All OutlookCode.com content
Viewing all 871 articles
Browse latest View live

VBA for BCM

$
0
0
Hi all, Is it possible to write VBA code that exports BCM business data to CSV file? I read that VBA on BCM is possible since it is associated with Outlook. But, I am not sure where to look for objects and properties for BCM. Is it the same as Outlook object? What if the data I want to export is from a customized record type. Is it possible to select that customized business data?

Can I use the MailItem Close Event?

$
0
0
I want to trigger a macro when a message is closed. The only code I found so far is: Public WithEvents myItem As Outlook.MailItem Public Sub Initalize_Handler() Set myItem = Application.ActiveInspector.CurrentItem End Sub Private Sub myItem_Close(Cancel As Boolean) [desired functions] End Sub However, there is no indication how/when to invoke Initalize_Handler, or whether this will work properly if multiple messages are openend.

Outlook 2007 Contact Form

$
0
0
When you use the design mode to design a custom Contact form in Microsoft Office Outlook 2007, the design form that appears has a different layout than the default Contact form. Additionally, the Add Contact Picture option does not appear in the design mode Contact form as expected. Is there a way to design a custom Contact form in Microsoft Office Outlook 2007 where the design form that appears is the same layout of the default Contact form?

Find not found subject with different Class

$
0
0
Hello, How can I use "find" methode to research a subject if the objects are with different Class (mail, meeting, etc..) ?

Print emails & attachments in batch without any prompts

$
0
0
Hi, I've tried to write a macro in Outlook to batch print selected emails & attachments. It works, but it seems to print the selected emails and attachments randomly... I'm getting really confused as to how I am supposed to make this work correctly... I usually write macros in Excel and Outlook seems so different... Also, I'd like to disable all the warnings I'm getting when the attachments are opened & closed... I read about that and it seems that there is no way to remove those prompts. Plus, Application.DisplayAlerts that I use in Excel doesn't work in Outlook. Can someone help? Here is my code so far: Option Explicit Sub Printemailswithattachments() Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim Response As Integer Dim msg As String Dim strSubject As String On Error Resume Next Set objOL = CreateObject("Outlook.Application") ' Trouver la sélection d'objects à imprimer Set objSelection = objOL.ActiveExplorer.Selection ' Voir si il y a des PJ For i = objSelection.Count To 1 Step -1 lngCount = objSelection(i).Attachments.Count If lngCount > 0 Then strSubject = objSelection(i).Subject If strSubject = "" Then msg = "Selected item #" & i Else msg = strSubject End If 'Response = MsgBox(msg & " has attachments." & vbCr _ '& "Do you wish to delete?", vbYesNo) 'If Response = vbNo Then objSelection(i).PrintOut 'Else ' objSelection(i).PrintOut ' objSelection(i).Delete 'End If Else objSelection(i).PrintOut 'objSelection(i).Delete End If Next ExitSub: Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub Thank you!

Reading Caption from a Radio Button in a custom form

$
0
0
I have a frame that contains a number of radio buttons. These buttons are bound to the same field - CostType. Each button has a different Caption, e.g. Red, Blue, Green. I cannot find a way of retrieving the Caption value using VBScript. I suspect it cannot be done. Does anyone know how?

Please help im going crazy

$
0
0
hi I can find many vba codes that convert plain text email to hmtl in outlook and they work. but my html signature doesn't get inserted. I have tried and tried. please help. Option Explicit Dim strbody As String Dim SigString As String Dim Signature As String Dim OutMail As Object Private WithEvents oExpl As Explorer Private WithEvents oItem As MailItem Private bDiscardEvents As Boolean Private olFormat As OlBodyFormat Private Sub Application_Startup() Set oExpl = Application.ActiveExplorer bDiscardEvents = False 'olFormat = olFormatPlain '(*1) - uz.ywaj zawsze formatu "zwyk?y tekst" olFormat = olFormatHTML '(*2) - uz.ywaj zawsze formatu HTML End Sub Private Sub oExpl_SelectionChange() On Error Resume Next Set oItem = oExpl.Selection.Item(1) End Sub ' (*3) Uz.ytkownik wybra? polecenie "Odpowiedz" Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean) If bDiscardEvents Or oItem.BodyFormat = olFormat Then Exit Sub End If '(*4) Anuluj domys'lna; akcje; Cancel = True bDiscardEvents = True ' (*5) Utwo'rz odpowiedz' na wiadomos'c' w formacie tekstowym Dim oResponse As MailItem Set oResponse = oItem.Reply oResponse.Display oResponse.BodyFormat = olFormat On Error GoTo 0 Set OutMail = Nothing ' Set OutApp = Nothing bDiscardEvents = False End Sub ' (*6) Uz.ytkownik wybra? polecenie "Odpowiedz wszystkim" Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean) If bDiscardEvents Or oItem.BodyFormat = olFormat Then 'Change only Mysig.htm to the name of your signature SigString = Environ("appdat") & _ "Microsoft\Signatures\Sign.htm" If Dir(SigString) <> "" Then Signature = GetBoiler(SigString) Else Signature = "" End If On Error Resume Next With oItem ' .To = "ron@debruin.nl" ' .CC = "" ' .BCC = "" ' .Subject = "This is the Subject line" .HTMLBody = strbody & "<br><br>" & Signature 'You can add files also like this '.Attachments.Add ("C:\test.txt") ' .Send 'or use .Display End With Exit Sub End If Cancel = True bDiscardEvents = True Dim oResponse As MailItem Set oResponse = oItem.ReplyAll oResponse.BodyFormat = olFormat oResponse.Display bDiscardEvents = False End Sub ' (*7) Uz.ytkownik wybra? polecenie "Przes'lij dalej" Private Sub oItem_Forward(ByVal Forward As Object, Cancel As Boolean) If bDiscardEvents Or oItem.BodyFormat = olFormat Then Exit Sub End If Cancel = True bDiscardEvents = True Dim oResponse As MailItem Set oResponse = oItem.Forward oResponse.BodyFormat = olFormat oResponse.Display bDiscardEvents = False End Sub Function GetBoiler(ByVal sFile As String) As String 'Dick Kusleika Dim fso As Object Dim ts As Object Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2) GetBoiler = ts.readall ts.Close End Function

Accessing Outlook Personal & Organization Forms

$
0
0
Hello, I have a program that allow users to select Outlook forms from Organizational Forms Library or from Personal Forms Library. The program used CDO 1.2.1 to find the Organizational Forms and Common View folders. We are now migrating to Outlook 2010 and CDO 1.2.1 is not supported anymore. How do I find this folder using Outlook 2010 object model? TIA

Add macro buttons to search by Color Categories in 2010 Ribbon

$
0
0
Hi all, This is probably a simple question, but I'm having trouble getting the right syntax. I'm using Outlook 2010 and I would like to customize the ribbon to add the ability to search by individual Color Categories. Now, I can easily new tabs to the ribbon and add a new group with the 'Categorized' button, but this only gives me a drop-down of the 15 most used categories. What I would like to do is expand this, so I have extra buttons that match particular categories. For example, click on button "Apple" which would throw the text (category:="Apple") into the search bar. Then, have another button "Banana" which would append the text (category:="Banana") in the search bar, etc. As I have now decided to use color categories instead of folders, this would help me to search a lot faster. Please let me know if you have the VBA to do this. Thanks, John

add unread mail to favorite folder outlook2010 by VBA

$
0
0
I am using Outlook2010, I want to deploy a VBA to help all user add "unread mail" to favorite folder, can you help to give a reference code?

Responding to Task form Save, Close or Send

$
0
0
I am trying to automate a process where I delegate a received email to a subordinate by creating a new task. I have written the code that will create the new task item and transfer the body of the email to the body of the task, put the task in assign mode. If I send the item I want to move the email to another folder or delete it entirely. How do I determine if the user has pressed send or has closed the new task without sending it. If I close the new task by clicking the X in the upper right corner it still creates the task in the task folder. Your help is appreciated. Sub CPFDelegate() Dim oApp As New Outlook.Application Dim oExp As Outlook.Explorer Dim oSel As Outlook.Selection Dim oItem As Object Dim mBody As String Dim mSubject As String Dim mTrue As Boolean Set oExp = oApp.ActiveExplorer Set oSel = oExp.Selection Set oItem = oSel.Item(1) mBody = oItem.Body mSubject = oItem.Subject ' Set myItem = Application.CreateItem(olTaskItem) RunMyForm (mBody), (mSubject) ' oItem.Delete End Sub Sub RunMyForm(mBody As String, mSubject As String) Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Dim myItems As Items Dim myItem As Object Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myFolder = _ myNameSpace.GetDefaultFolder(olFolderTasks) Set myItems = myFolder.Items Set myItem = myItems.Add("IPM.Task.GTDTaskForm") ' Set myItem = CreateItem(olTaskItem) Dim objProperty As Outlook.UserProperty Dim UserDefinedFieldName As String UserDefinedFieldName = "Action" Set objProperty = myItem.UserProperties.Add(UserDefinedFieldName, Outlook.OlUserPropertyType.olText) objProperty.Value = "@Waiting For" myItem.Assign myItem.Subject = mSubject ' myItem.Categories = "@Waiting For" myItem.Body = mBody myItem.Display ' myItem.Display ' Set myOlApp = Nothing ' Set myNameSpace = Nothing ' Set myFolder = Nothing ' Set myItems = Nothing '' Set myItem = Nothing End Sub Thanks Charles

Changing font in Outlook

$
0
0
I have code from excel to create an email and copy data to the email. The information copied over always goes to times new roman, and I need it to be in Calibri 11. Appreciate any help I can get, thanks. Sub Mail_Outlook_With_Signature_Html() Dim OutApp As Object Dim OutMail As Object Dim strbody As String Dim SigString As String Dim Signature As String If Range("a2") = Empty Then MsgBox "Select Service and try again." Exit Sub End If If Range("b2") = Empty Then MsgBox "Select Issue and try again." Exit Sub End If If Range("a5") = Empty Then MsgBox "Select Calls in Queue and try again." Exit Sub End If If Range("b5") = Empty Then MsgBox "Select Minutes and try again." Exit Sub End If If Range("a8") = Empty Then MsgBox "Select Number of Agents or Managers and try again." Exit Sub End If If Range("b8") = Empty Then MsgBox "Select Status and try again." Exit Sub End If If Range("h2") = Empty Then MsgBox "Select Cause and try again." Exit Sub End If MsgBox "Please review the body of your email before you send." Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) SigString = Environ("appdata") & _ "\Microsoft\Signatures\Santander.htm" If Dir(SigString) <> "" Then Signature = GetBoiler(SigString) Else Signature = "" End If On Error Resume Next With OutMail .To = Sheets("Communications").Range("a17") .CC = "my team" .BCC = "" .Subject = Sheets("Communications").Range("a20") .HTMLBody = Sheets("Communications").Range("a25") & Signature .Display End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub

Custom Outlook form with Voting Options

$
0
0
Hello, I am currently designing a custom form. This form is meant as a workflow-form. In that case I want to use Voting Buttons; to Approve; DisApprove The form is created in Outlook 2010, and has VBScript-code in backend. My Question is; what is the VBScript-code for "handling" Voting-button-options? I want to customize the reply and storage for Voting-buttons (such as archive), and more. I tried to insert Options - Use Voting Buttons-ribbon, and the customizing there, but it didn't seem to work. And besides, I do want to do this by VBScript-code. <code> 'Create a new message set objOutlk = createobject("Outlook.Application") set objMail = objOutlk.CreateItem(olMailItem) With objMail .To = SendTo .cc = ComboMyManager .bcc = CurrentUser .body = strMsg .Importance = olImportanceHigh .VotingOptions ="Disapprove;Approve" &vbcrlf & intNumber set objAction = objMail.Actions.add With objAction .CopyLike = olRespond .Enabled = True .Name = "Approve" .ReplyStyle = olOmitOrginalText .ResponseStyle = olPrompt .ShowOn = olMenuAndToolbar End with </code>

Search for exact phrase with AdvancedSearch

$
0
0
Hello everybody, I have the following 3 subjects: 1/ RE: can't 2/ RE: can't xx 3/ can't Is it possible to reseach with « AdvanceSearch » method this subject ? In the loop, the first time, sujet = can''t the second time, sujet = can''t xx the third time, sujet = can't strS = Chr(39) & myFolder.FolderPath & Chr(39) strF = Chr(34) & " urn:schemas:httpmail:subject" & Chr(34) & " LIKE " & "'%" & sujet & "'" strTag = "SubjectSearch" Set yy = Application.AdvancedSearch(strS, strF, False, strTag) Do While Not AdvancedSearchComplete DoEvents Loop Set rsts = yy.Results result = rsts.Count Debug.Print "Number of results: " & result In the result, I expect : Number of results: 2 for first and third subject Number of results: 1 for second subject And not Number of results: 3 for all subject Do you think it is possible to do this search ? Thanks by advance for your answer. Regards,

VBscript to create new folder and custom views from inside outlook form

$
0
0
Hello all, I have an outlook form in 2007. I would like to add a command button in the form that will: 1.create a sub-folder under the inbox called "Forms to Approve" if it doesn't already exist. If it does exist then termite the whole process. 2. Create a rule that will direct new messages to this folder based on words in the subject beginning with "ReqMgrAppr". 3. Remove all columns in the newly made folder then create a custom view in the folder based on 5 fields in the form then return some of the standard columns fields such as Icon, Flag, From, Category. I hope this is clear and I do appreciate any help. R/Mja

Outlook is not fully closing ...

$
0
0
I have written the following add-in for myself in VS2010 to run in Outlook 2007. It accesses a basic SDF SQLCE database & appears to work just fine ... except Outlook remains open with a Crossed grey icon in the System Tray ... can anybody tell me why ?!? [code]Imports Microsoft.Office.Interop.Outlook Imports System.Data.SqlClient Imports System.Data.SqlServerCe Public Class ThisAddIn Private Sub ThisAddIn_Startup() Handles Me.Startup End Sub Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown End Sub Private Sub Application_NewMailEx(EntryIDCollection As String) Handles Application.NewMailEx Dim MyConn As SqlCeConnection = New SqlCeConnection("Data Source=j:\Users\Gary\Visual Studio 2010\Projects\My_Rules\My_Rules\My_Rules.sdf") Dim MyApp As Outlook.Application = New Outlook.Application Dim MyNS As Outlook.NameSpace = MyApp.GetNamespace("MAPI") Dim MyInbox As Outlook.MAPIFolder = MyNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) Dim MyEmails As Integer = MyInbox.Items.Count Dim MyEmail As Outlook.MailItem Dim MyCount As Integer Dim MySubFolder As Outlook.Folder = GetMyFolder("Outlook (Gary)\Kickabout") Dim MyDest As String Dim MySqlCeCmd As New SqlCeCommand() Dim MyRecord As SqlCeDataReader MyConn.Open() For MyCount = MyEmails To 1 Step -1 MyEmail = MyInbox.Items(MyCount) If MyEmail.SenderEmailAddress = "chris.spelbinder@btinternet.com" Then MySubFolder = GetMyFolder("Outlook (Gary)\Kickabout") If MyEmail.Attachments.Count > 0 Then MySubFolder = GetMyFolder("Outlook (Gary)\Kickabout\Attachments") End If MyEmail.Move(MySubFolder) Else MySqlCeCmd = New SqlCeCommand("Select * from Emails where EmailAddresses = '" + MyEmail.SenderEmailAddress + "'", MyConn) MyRecord = MySqlCeCmd.ExecuteReader() While MyRecord.Read MyDest = "" + MyRecord(1) + "" MySubFolder = GetMyFolder(MyDest) MyEmail.Move(MySubFolder) End While End If Next MyConn.Close() End Sub Function GetMyFolder(FolderPath) ' folder path needs to be something like ' "Public Folders\All Public Folders\Company\Sales" Dim aFolders Dim fldr Dim i Dim objNS Dim strFolderPath As String On Error Resume Next strFolderPath = Replace(FolderPath, "/", "\") aFolders = Split(FolderPath, "\") 'get the Outlook objects ' use intrinsic Application object in form script objNS = Application.GetNamespace("MAPI") 'set the root folder fldr = objNS.Folders(aFolders(0)) 'loop through the array to get the subfolder 'loop is skipped when there is only one element in the array For i = 1 To UBound(aFolders) fldr = fldr.Folders(aFolders(i)) 'check for errors 'If Err() <> 0 Then Exit Function Next GetMyFolder = fldr ' dereference objects objNS = Nothing End Function End Class [/code]

Exchange 2007 service pack or roll-up broke VBA?

$
0
0
This code has worked perfectly for many months and now that our helpdesk has applied a service pack and a roll-up on our exchange server - it fails saying that the exchange server is not available. It blows up on this line - is there something that needs to change for the current service pack of exchange 2007? Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)

Contacts... multiple in one contact

$
0
0
when selecting the standard 'field and Format of control' command button and text box. It inserts a command button that when clicked asks to link a contact. that what i want to do but i want to link recreate this comand button and text box several times but each one uniquie so that the user can click the button, and link the contact but then click the next button and link another contact however when i have created this in developer it fills the text boxes in with the same data as all the other command buttons and text boxes. Is there anyway of recreating this control but make each field unique within the same contact.

Setting named properties

$
0
0
Hi - hope a guru here might be able to help me. Been trying to find a solution to this for months... With an account email address of: "DoNotReply <DNR@domain.com>" And Setting the named properties to: "Sambo <sambo@domain.com>" The following MIME headers result: 1) Setting "From" named property results in "From" MIME Header: "Sambo" <sambo@domain.com>, "DoNotReply" <DNR@domain.com> 2) Setting "Sender" results in "Sender" Mime Header: "Sambo" <sambo@domain.com> 3) Setting both "From" and "Sender" properties: Both "From" and "Sender" MIME Headers are set to: "Sambo" <sambo@domain.com>, "DoNotReply" <DNR@domain.com> 4) Instead of setting the "From" and "Sender" properties via code, manually type "Sambo <sambo@domain.com>" into the "From:" box results in "From" MIME Header: "Sambo" <sambo@domain.com> How can I get option 2 and 4 via code (i.e. without having to manually type in the "From:" box)? Using Outlook 2007. Here is test code: Option Explicit Dim propertyAccessor As Outlook.propertyAccessor Private Sub Application_xItemSend(ByVal Item As Object, Cancel As Boolean) Dim strSender As String strSender = "Sambo A <Sambo@w3x4.com>" Set propertyAccessor = Item.propertyAccessor propertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/From", strSender propertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/Sender", strSender 'Item.Save End Sub I sure would appreciate any help -- thanks Sam

VBA 6.3 verusu VBA 7.0

$
0
0
I have inherited some VB coding for Outlook which was created using VBA 6.3.Our PCs have been upgraded to Outlook 2010 (along with VBA 7.0), however, the other office apps are still 2002. When we try to run the code on a PC with Outlook 2010 but with VBA 6.3 it errors with Run Time Error 5 Invalid Procedure Call or argument.It then refers to a line which is "rpl.BodyFormat = olformatHTML." Does anyone have any idea why? Thanks
Viewing all 871 articles
Browse latest View live