19255

create a contact in a non-default outlook contact folder

Question:

<blockquote>

Hi, I would like to create a contact in a non-default outlook contact folder with Excel VBA 2010. In this example, the folder name is “azerty”, located in \mypersonnal_pst\Contacts I tried unsuccessfully :

</blockquote> Dim myolApp As Outlook.Application Dim myNamespace As Outlook.Namespace Set myolApp = CreateObject("Outlook.Application") Set myNamespace = myolApp.GetNamespace("MAPI") Set Folder = myNamespace.GetDefaultFolder(olFolderContacts).Parent.Folders("azerty") Set objContact = myolApp.CreateItem(olContactItem) With objContact .Email1Address = "example@ex.com " .FirstName = "Joe" .LastName = "Mc" .HomeTelephoneNumber = "99 99 99 99 99" .HomeAddressCity = "Xlcity" .Save End With <blockquote>

I have tried your example 'addnewcontacts'. It does not work. I would appreciate any help. Thks

</blockquote>

Answer1:

If you need to create an Outlook item in the specific folder use the <a href="https://msdn.microsoft.com/en-us/library/office/ff861028(v=office.15).aspx" rel="nofollow">Add</a> method of the Items class instead.

Dim myolApp As Outlook.Application Dim myNamespace As Outlook.Namespace Set myolApp = CreateObject("Outlook.Application") Set myNamespace = myolApp.GetNamespace("MAPI") Set Folder = myNamespace.GetDefaultFolder(olFolderContacts).Parent.Folders("azerty") Set objContact = Folder.Add(olContactItem) With objContact .Email1Address = "example@ex.com " .FirstName = "Joe" .LastName = "Mc" .HomeTelephoneNumber = "99 99 99 99 99" .HomeAddressCity = "Xlcity" .Save End With

Or move the item to the target folder using the <a href="https://msdn.microsoft.com/en-us/library/office/ff869633(v=office.15).aspx" rel="nofollow">Move</a> method after creation.

Dim myolApp As Outlook.Application Dim myNamespace As Outlook.Namespace Set myolApp = CreateObject("Outlook.Application") Set myNamespace = myolApp.GetNamespace("MAPI") Set Folder = myNamespace.GetDefaultFolder(olFolderContacts).Parent.Folders("azerty") Set objContact = myolApp.CreateItem(olContactItem) With objContact .Email1Address = "example@ex.com " .FirstName = "Joe" .LastName = "Mc" .HomeTelephoneNumber = "99 99 99 99 99" .HomeAddressCity = "Xlcity" .Save .Move Folder End With

You can read more about that in the <a href="https://www.add-in-express.com/creating-addins-blog/2011/10/07/outlook-create-contact-item/" rel="nofollow">How To: Create a new Outlook Contact item programmatically</a> article.

Recommend

  • Method being called, but not executing properly
  • Initialize and allocate multiple variables/objects | Objective C
  • Next step to Make Binding for embedded framework for Xamarin.iOS?
  • Generic method with return type as object [duplicate]
  • Finding folders back based on a predefined folder structure
  • No Symbols found for architecture. Xcode 4.3
  • Swift/ObjC circular import
  • CMake script for CUDA 6.0 with C++11
  • Rotating NSString in Swift
  • Can't access My Swift classes into Objective-C application
  • Why is the @objc tag needed to use a selector?
  • wxPython Mac OS X Fullscreen work around error
  • Objective C Multi thread NSWindow alternative?
  • Custom navigationBar on moreNavigationController
  • Hi I am trying to execute the Wikitude sample application, but I am getting these compile errors, pl
  • Unable to add google sign in in ios 9.0
  • How to access swift public function in objective c files?
  • Real ads (admob) not showing up in Live app
  • target_compile_options() for only C++ files?
  • jdom removes duplicate namespace declaration (xmloutputter)
  • Property with redefined accessor still accessible
  • Custom outlook plug in not downloading as expected
  • mobile first cli project deploy failing
  • iOS - Can anyone suggest me how can I integrate gmail account into my app and get the list of all em
  • Google Ads using FireBase + CocoaPods gives error: “duplicated symbols for architechture x86_64”
  • Set all mail items in an outlook conversation to read using VBA
  • Is it possible to write an outlook add-in that modifies the color of the user interface?
  • How to implement AVCam for Swift
  • Changing UIView rotation will change it's frame size. How to keep frame size after rotating?
  • How to parse an object to obtain keys values (attribute/value) in Objective-C? [closed]
  • Memory usage of a C program under Windows [duplicate]
  • Programmatically change height of navigation bar in swift
  • VBA dialog boxes automatically answer solution
  • Automatically Allow Programmatic Access to Outlook
  • How do I declaratively bind 'SelectedValue' to datasource field?
  • Is it possible to install cupy on google colab?
  • What is the convention to use boolean for gender in programming languages? true male false female? [
  • PR_INTERNET_MESSAGE_ID returns blank when sending message
  • Upgrading from Google Sign-In SDK 1.0.0 to 2.0.1 fails to compile on SKStore references
  • Monotouch Linea Pro SDK issue with build arguments
  • What does @interface DITableViewController (private) mean?
  • How to read email and retrieve attachement using CDO (Collaborative Data Object) in VB6?
  • JSONserialization error
  • Serializing C# classes to MongoDB without using discriminators in subdocuments
  • Storing image in dojo datagrid
  • @objc protocol crashes the swift compiler
  • Swift Crash: Array._allocateBufferUninitialized
  • Changing “src” of an “img” html element doesn't refresh it
  • Listing all emails on a shared mailbox with attachments name
  • Fusion Table in Google Maps will not display entire geometry layer
  • What is the difference between Root Class & Base Class in Objective-C?
  • Axis2 web service error: services.xml not found
  • Calling base class functions through derived pointers
  • Run all tests in namespace using Nunit3-console.exe
  • Optional Protocol Requirements, I Can't Get It To Work
  • Magento Enterprise controller override
  • JavaFX: Mouse clipboard does not work in Unix
  • Warning: the current language does not match this frame
  • collatz-list implementation using haskell
  • Connect to a password protected server with WCF over HTTP
  • disabling ARC for .h files iphonesdk
  • Are IEnumerable collection supported in EF 4.1 for mapping?
  • “Member has private access error” after deleting plugin in CakePHP using PhpStorm
  • How to move cursor from one text field to another automatically when the user clicks the Delete Butt
  • windows “.lnk” shortcuts and batches don't mix
  • Execute some function after raw push notifications is received from server in Window Phone 8.1
  • How to fetch the alt value from an img using vba
  • Read files from URL
  • Pasting URLs That Have Been Scraped From a Webpage
  • How to add System.Windows dll to Visual Studio 2010 express?
  • C++ Coin flip program error
  • string.IsNullOrEmpty() Doesn't Seem to Work on a String within a Class within a Class
  • Removing Duplicate Geometries
  • WPF Template Binding in ToggleButton UserControl
  • Web.config system.webserver errors
  • Change Inet root folder for iis 7
  • Paperclip, set path outside of rails root folder
  • Spring Data JPA custom method causing PropertyReferenceException
  • C# - Serializing and deserializing static member
  • Volusion's generic SQL folder, functionality
  • Sending data from AppleScript to FileMaker records
  • Adding custom controls to a full screen movie
  • How to include full .NET prerequisite for Wix Burn installer
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • Is it possible to post an object from jquery to bottle.py?
  • Append folder name and increment by 1 using batch script
  • Checking variable from a different class in C#
  • reshape alternating columns in less time and using less memory