Outlook being closed causing problems during copy to Excel

Status
Not open for further replies.

bnj1776

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
I've used "Set objOutlook = New Outlook.Application" in my Excel VBA, but while I'm copying Contacts to an array and the user closes Outlook, Excel dies with

Run-time error '462':
The remote server machine does not exist or is unavailable.​

Is there any way to prevent this error within the Excel VBA?

Thank you,
Brian
 

bnj1776

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Added test to prevent copy from even starting if Outlook open, but with thousands of contacts the user can still open & close Outlook causing the problem while the copy is running.
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You cannot really prevent the user closing Outlook but you can catch the error in your code. For instance
Code:
on error goto err_handler
'do your stuff here
exit sub
err_handler:
msgbox err.description
 

bnj1776

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Error trapping added for this, but not finding any way to easily resume to the middle of for next loop of all contact items.

Not able to sort by EntryID??? Am I missing something here???

Otherwise if initially the Contact Items were sorted by LastModificationTime, restricting the continued pass by LastModificationTime > last record successfully copied should work correctly.

Thanks
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Code:
err_handler:
resume next
resumes at the line after the one that raised the error.

Why do you want to sort by EntryID? LastModificationTime is a way to go. See the Items.Sort function, which is explained in the VBA help file.
 

bnj1776

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
My attempts to sort by EntryID creates:
Run-time error '-2147467259 (80004005)'
The operation failed.​
I've looked at the MSDN Items.Sort Method page many times. EntryID is not on the list of Cannot Be Used specifically, so it must fall under "Category" or "Class"???

With 4000+ contacts it takes some time to copy them all from Outlook to Excel. So I was trying to sync only Outlook changes to Excel. To me sorting both data sets by EntryID would be the best way to go via For Next loops to sync adds, mods & deletes from Outlook to Excel. I was trying this in hopes that the testing and the skipping of matches would be faster than pulling a full copy of everything from Outlook. I can certainly do a full copy to a temporary table, sort and compare, but that means I've just done a full download PLUS the time to sync the two tables. This would take more time, not less.

Maybe EntryID is not the key field normally used in this type of operation? I'm new to Outlook and assumed such a field would be the best to key on, but apparently not. I was worried about using CompanyAndFullName as those are user changeable fields, but that field appears to be the only option for syncing. Or am I missing one that would be better?

Regarding the error created by the user closing Outlook (FYI opening Outlook while the VBA code is running is not an issue). The database links created by the VBA code simply disappear when the user closes Outlook while the VBA code is running. Effectively "Set objOutlook = Nothing" randomly in the middle of Excel's VBA code. This surprises me as I thought that the "Set objOutlook = New Outlook.Application" was creating a new and separate instance of Outlook that would be unaffected by the user's actions. This is not the case in my testing. Maybe I am not setting up my link to Outlook correctly??? Regardless, "Resume Next" fails because the connection to Outlook has been lost, completely. Maybe I'm wasting my time, but I'm working on reconnecting an picking up where the "interruption" happened now because I prefer to "bullet proof" my code.

Outlook's "features" are very frustrating and I'm in hopes that I'm missing something magical that will save me all this trouble... So if you have any ideas, please, please share.

Thank you.
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
See my comments about Entryid vs. LastModificationTime.

It's obvious that a simple 'resume what has already failed' has no benefit at all. I just demonstrated how to create an error handler. In the error handler check the error number or if the Outlook variable is nothing, re-set all the variables, then re-start the export.

You cannot create multiple instances of Outlook.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C Outlook 2016/2019 hangs after being open for an extended period Using Outlook 4
GregS 2016 Contact List being managed by Outlook.com? Using Outlook 1
B Outlook - Mail from safe senders list being sent to Spam Folder Using Outlook 0
T Compacting Outlook 2010 OST results in old emails being re-sent Using Outlook 6
M Upgrade in Progress. Your mailbox is currently being optimized as part of upgrade to Outlook 2010 Using Outlook 9
H Preventing the Send button from being clicked on an Outlook Form Outlook VBA and Custom Forms 1
S Calendar items are not being uploaded to outlook.com after copying Using Outlook.com accounts in Outlook 1
R Mailto link inside Outlook 2010 being cached? Using Outlook 1
L Outlook underlining all text after being sent to recipient Using Outlook 3
J How to Stop OutLook from being Installed Using Outlook 1
P VBA Code being completely ignored by Outlook Using Outlook 7
Terry Sullivan Android Phone E-Mails Not Disappearing After Being Deleted in Outlook 2013 Using Outlook 5
B Permissions - Outlook Public Folders Are Being Deleted Using Outlook 1
P How to know Outlook is being started in Offline mode? Outlook VBA and Custom Forms 2
M Outlook 2007 with BCM - Tasks being created automatically BCM (Business Contact Manager) 1
D Outlook 2016 Outlook Error Msg "The operation cannot be performed ..." How to Stop it Using Outlook 0
D Outlook.com premium finally dying... what do I do with my domain? Using Outlook.com accounts in Outlook 3
witzker Outlook 2019 is cutting Picture Extension *.pn_ Using Outlook 3
S Is there a free version of outlook? Using Outlook 0
peterbata Shared Tasks Outlook for Mac Using Outlook 2
L Ideas for Setup with New Office 365 Family Subscription (Outlook) Using Outlook.com accounts in Outlook 3
M Issue transferring Outlook 2016 email accounts & settings onto new computer Using Outlook 8
S Excel vba code to manage outlook web app Using Outlook 8
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 1
H Custom Outlook Contact Form VBA Outlook VBA and Custom Forms 1
P Outlook 2013 Calendar Archiving Using Outlook 0
D Connecting Gmail to Outlook 365 - My Setup not working Using Outlook 2
K Outlook tasks formatting Using Outlook 4
G Retention Policy for Outlook.com Deleted Items folder Using Outlook 0
S Problem Checking the available stores in my Inbox (Outlook VBA) Outlook VBA and Custom Forms 0
V Is it possible to collect statistics from Outlook forms? Outlook VBA and Custom Forms 1
Z Outlook 365 delete reminder you can’t make change to contents of this-read only folder Using Outlook 4
H I have no profile listed for Outlook! Using Outlook 9
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
S Macro for Loop through outlook unread emails Outlook VBA and Custom Forms 2
D Outlook 2016 how to use gmail account as source account for outlook 365 Using Outlook 9
Horsepower Contacts added from iPhone don't show up in Outlook Using Outlook 1
F Microsoft Outlook Connector 14.0.6123.5001 - Help! Using Outlook 6
A Outlook (and Office) 2019 Logging Using Outlook 2
glnz Can Word Normal.dotm interfere with Outlook? Office 2016 Using Outlook 5
D Outlook 2016 and Earlier with Office365 in 2021 Using Outlook 3
glnz Moving from Outlook 2003 to MS365 Outlook - need basics Using Outlook 4
L Outlook saved template function too limited Using Outlook 2
C Looking for feedback on new Outlook Add-in Using Outlook 0
M Outlook on 3 Computers Shows Different Total Items on Same Account Using Outlook 3
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
witzker print-list-of-outlook-folders with sort posibility Outlook VBA and Custom Forms 7
witzker Open Contact missing in Outlook 2019 Using Outlook 2
D.Moore VB script to Digitaly Sign newly created outlook message Outlook VBA and Custom Forms 2
B Outlook 2016 Retail C2R keeps logging since update? Using Outlook 0

Similar threads

Top