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.
Thread starter Similar threads 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
G How can I stop duplicate e-mails being sent to my sent folder in Outlook 2010? Using Outlook 2
J Secondary Outlook 2007 Mailbox keeps disappearing from Users Outlook Folder List dispite her being d Using Outlook 2
K Sending email in Outlook - being able to choose... Using Outlook 1
S OUTLOOK 'FORBIDS' MY MESSAGES FROM BEING SENT FROM OUTBOX.... Using Outlook 1
R Outlook 2010: Text in Body Being Change, HTML tags/code showing Using Outlook 3
F Messages get marked as read in Gmail after being downloaded by Outlook Using Outlook 2
M Outlook 2007 - Emails being delivered to unspecified Recipient Mailbox Folder. Using Outlook 1
I Reminder on Sent Msg being removed upon next Send/Receive execution in Outlook Using Outlook 1
Z You cannot delete this outlook data file. Configuration information in the file is being copied. You Using Outlook 1
A When deleting e-mails in Blackberry, e-mails in Outlook also being deleted Using Outlook 1
N Emails sent from Outlook 2010 are being received with some corruption of the body text Using Outlook 37
B how to add my own imap email account with full calendar privileges to exchange/outlook to avoid invites being sent 'on behalf of' my exchang Using Outlook 2
R Outlook Calendar Invites being sent Email not Invite (no Accept or Decline Buttons) Using Outlook 1
M I want to restore my inbox emails in yahoo server after being transfered to microsoft outlook. Using Outlook 2
N Emails sent from Outlook 2010 are being received with some corruption of the body text Using Outlook 2
J Outlook - how can I get emails back which I did not receive due to my mailbox being full? Using Outlook 3
G Prevent my AT&T email from being imported into Outlook 2003 when I open outlook. Using Outlook 1
G Email messages being received but not displayed until the next day on Outlook 2010 Using Outlook 2
I Some Messages Remain in Preview Pane After Being Deleted (Outlook 2010) Using Outlook 5
N Emails sent from Outlook 2010 are being received with some corruption of the body text Using Outlook 2
S In Outlook 2010 I am getting requests for meetings that are being automatically accepted and I am ne Using Outlook 1
N Emails sent from Outlook 2010 are being received with some corruption of the body text Using Outlook 5
D I have a new Dell Notebook, OS Windows 7 and Outlook 2010. When I send an email it shows as being sent, but it never arrives anywhere. Using Outlook 1
S Up to about a month ago, everything with my Outlook 2010 was fine. Then, I found out that my sent messages weren't being received and I did not get n Using Outlook 1
S Outlook reply window default tabs have changed from message being active, to now File being active. Using Outlook 1
S Outlook 2007 / Exchange 2003 - Single-Instance "Resource" Requests Auto-Denied as being recurring? Using Outlook 3
N Outlook 2010, File Attachments, not being received by recipients, replaced with "winmail.dat" attach Using Outlook 35
C Prevent clients outlook anywhere URL from being changed by autodiscover? Using Outlook 4
A Duplicate emails being displayed in Outlook Using Outlook 9
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
P outlook 2008 search box criteria couldn't be saved Using Outlook 2
pcunite Outlook 2019/O365 Build 13127.20408 errors when using MAPI calls Using Outlook 0
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 1
D Outlook 2010 Outlook in Windows 10 keeps asking for user name and password repeatedly Using Outlook 13
S Outlook mail adressing stops after first match in GAL Using Outlook 0
A Apply Selected Emails to outlook rules and Run Rules Using Outlook 5
Similar threads


















































Top