VBA Outlook Contacts

efire9207

Member
OS Version(s)
  1. Windows
Outlook version
Outlook 365 64 bit
Email Account
IMAP
Operating system::    Windows 2011
Outlook version:     Microsoft 365
Email type or host:    IMAP

Need a VBA to bulk move File As to First Name... anyone have something I can use .....
 
I have a macro at Bulk Change File As Format for Contacts and a PowerShell at



If you need to use the File As as the first name field if would be this for a macro -

Code:
  With objContact
            
                'Firstname Lastname format
                 strFileAs = .FullName
              
                'Lastname, Firstname format
                ' strFileAs = .LastNameAndFirstName
              
                'Company name only
                ' strFileAs = .CompanyName
              
                'Companyname (Lastname, Firstname)
                ' strFileAs = .CompanyAndFullName
                
               .firstname = .fileas 

                .Save
            End With


and powersahell should be

Code:
foreach ($Contact in $Contacts.Items)
{
    {
   $Contact.firstname = $Contact.fileas
   $Contact.Save()
 
I have a macro at Bulk Change File As Format for Contacts and a PowerShell at



If you need to use the File As as the first name field if would be this for a macro -

Code:
  With objContact
           
                'Firstname Lastname format
                 strFileAs = .FullName
             
                'Lastname, Firstname format
                ' strFileAs = .LastNameAndFirstName
             
                'Company name only
                ' strFileAs = .CompanyName
             
                'Companyname (Lastname, Firstname)
                ' strFileAs = .CompanyAndFullName
               
               .firstname = .fileas

                .Save
            End With


and powersahell should be

Code:
foreach ($Contact in $Contacts.Items)
{
    {
   $Contact.firstname = $Contact.fileas
   $Contact.Save()
I copied and pasted into VBA in Outlook, then when I run it I get this error 'Compile Error, Invalid Outside Procedure". the Contact Folder name is 'Contacts (This Computer Only) is that the problem?
 
I copied and pasted into VBA in Outlook, then when I run it I get this error 'Compile Error, Invalid Outside Procedure". the Contact Folder name is 'Contacts (This Computer Only) is that the problem?
No, not necessarily. More likely there is an error in the code.

Was the folder selected or is it in the default data file?

This code (from powershell, but is similar in VBA) - uses the default contacts folder by default - but could be changed to the selected folder.

# Default Contacts folder
$Contacts = $namespace.GetDefaultFolder(10)

# Uses current folder
#$Contacts = ($olApp.ActiveExplorer()).CurrentFolder

This should work on the selected contacts folder
Code:
$olApp = new-object -comobject outlook.application
$namespace = $olApp.GetNamespace("MAPI")

# Uses current folder
$Contacts = ($olApp.ActiveExplorer()).CurrentFolder

foreach ($Contact in $Contacts.Items) {    
{   
$Contact.firstname = $Contact.fileas
   $Contact.Save()
    }
}

$olApp.Quit | Out-Null
[GC]::Collect()
 
I copied and pasted into VBA in Outlook, then when I run it I get this error 'Compile Error, Invalid Outside Procedure". the Contact Folder name is 'Contacts (This Computer Only) is that the problem?
So I ran the Macro, but it didn't seem to work completely.... I am wondering if I need to first run a macro to delete the First Name field first
 
No, it should replace the first name field - unless the only entry in the file as is the first name field, then it will appear as nothing changed.

Check the ones you think are not correct - click on the full name button to see where the entries are.
 
No, it should replace the first name field - unless the only entry in the file as is the first name field, then it will appear as nothing changed.

Check the ones you think are not correct - click on the full name button to see where the entries are.
When I check the First Name and File As are in a different order, so they didn't change... I tried adding the line of code you sent for Current Folder, not sure if I added it correctly to the Macro...
'Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)'
Set objContactsFolder = objOL.App.ActiveExplorer().CurrentFolder
 
Similar threads
Thread starter Title Forum Replies Date
S Outlook VBA Contacts Notes Outlook VBA and Custom Forms 0
D Redemption? Need rapid pull of Outlook Contacts, email + notes for VBA Using Outlook 1
M can't access outlook contacts from excel via VBA Outlook VBA and Custom Forms 4
C VBA in "New Outlook?" Using Outlook 0
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
J Outlook VBA to send from Non-default Account & Data Files Outlook VBA and Custom Forms 4
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
M Outlook 2016 outlook vba to look into shared mailbox Outlook VBA and Custom Forms 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
BartH VBA no longer working in Outlook Outlook VBA and Custom Forms 1
W Can vba(for outlook) do these 2 things or not? Outlook VBA and Custom Forms 2
richardwing Outlook 365 VBA to access "Other Actions" menu for incoming emails in outlook Outlook VBA and Custom Forms 0
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
C Outlook (desktop app for Microsoft365) restarts every time I save my VBA? Using Outlook 1
E Outlook 365 Outlook/VBA Outlook VBA and Custom Forms 11
J VBA for outlook to compare and sync between calendar Outlook VBA and Custom Forms 1
E Outlook VBA change GetDefaultFolder dynamically Outlook VBA and Custom Forms 6
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
K Outlook Office 365 VBA download attachment Outlook VBA and Custom Forms 2
V vBA for searching a cell's contents in Outlook and retrieving the subject line Outlook VBA and Custom Forms 1
B vBA for exporting excel file from outlook 2016 Outlook VBA and Custom Forms 3
S Excel vba code to manage outlook web app Using Outlook 10
H Custom Outlook Contact Form VBA Outlook VBA and Custom Forms 1
S Problem Checking the available stores in my Inbox (Outlook VBA) Outlook VBA and Custom Forms 0
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
O VBA Outlook Message Attachment - Array Index Out of Bounds Outlook VBA and Custom Forms 0
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 1
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S Find a cell value in excel using outlook vba Using Outlook 1
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5

Similar threads

Back
Top