Why won't VBA see a copied calendar in cache mode anymore?

Not open for further replies.


Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Dear Diane,

I’m writing to you because sometimes it seems as if you’re the only person who understands Microsoft Exchange and wants to help.

We have a resource calendar on MS Exchange 2010 we use to record employees’ offsite time. (That way managers and co-workers can see at a glance who’s in the office, who’s working from home, etc.) The only problem is Exchange resource calendars aren’t visible from mobile phones – only personal calendars are – and our security policies don’t allow publishing the calendar, so we wrote a VBA application (Outlook 2010) that copies a filtered version of the calendar to a secondary calendar folder in subscribers’ personal calendar folders. (As part of the subscription process, the person running the application had to be granted Owner permission on the subfolder – me, primarily, although other people act as backups.) The application was designed to run in cached mode, so that it wouldn’t require manual intervention if the Exchange servers were busy. Since we couldn’t run VBA as a server-side process, it ran on my personal instance of Outlook.

That worked fine from May, when the program was written, until a couple of months ago, when I had to forcibly shut down Outlook because it was hung, for some reason, and I wasn’t able to restart it. Tech support removed all my local files in the directory that contained the OST file, and we rebuilt the OST file a few times, but ever since that day, I’ve been unable to run the VBA app successfully in cached mode. The program always breaks immediately after the calendar is copied to a calendar folder in a shared account (shared by me and my backups). (Whenever the calendar is updated, it is copied to this temporary holding area because the program changes some settings and filters out items that don’t overlap with the 30-day window the users want to see, before it copies it to the subscribers’ folders.) The copied calendar is visible in Outlook, but for some reason VBA doesn't see it in cached mode anymore. The program breaks with a Runtime Error 91: "Object variable or With block variable not set" because the folder object variable that is supposed to be set when the calendar is copied, doesn’t get set, so nothing can be done with it. If the program is run in online mode, however, VBA has no problem recognizing the calendar – the object variable is set when the calendar is copied and the rest of the processes can be run on it.

I’ve been running the application in online mode as best I could ever since, but it’s not practical to do that in the long term, because we have users in India, and it means someone has to be watching the program 24/7 to respond to the prompts when the server is not available and to restart Outlook when we are disconnected from the server (which happens quite often).

Our Exchange support staff are baffled by the problem and they get no help from Microsoft, which says they won't support a custom program. But it's not the VBA program that needs troubleshooting. The copy function just doesn't set the variable in cached mode, even though the file has obviously been copied into the folder.

Have you any idea why this is happening?


Interesting that it runs online but not offline. I'm wondering if the ost file name changed and the vba is using a hardcoded path. That would explain why its working online but not offline.

Can you post the code that triggers the error - about 3 lines before it and 3 lines after.
Thanks so much for responding so quickly.

Yes, the tech support person did change the OST file name, but since they deleted all the files in the directory while troubleshooting, I don't recall what the original name was. I can find out, since it was probably a default name.

In cached mode, the program always breaks on the line indicated in red, below, the fourth line of a module called GetMobileCalendar. It fails because fldTmp (a folder variable declared at the beginning of the module) isn't set by the copy operation.

bCleanUp = CleanUpTmpCalendars()

If bCleanUp = True Then

Set fldTmp = fldConflCal.CopyTo(fldAdminCal)

fldTmp.Name = "CARDS Team Mobile Calendar" 'cached mode breaks here

'filter items based on Today + constant number of days out

dStartLimit = DateValue(Now)

FYI, fldConflCal and fldAdminCal are global folder variables set when Outlook loads. fldConflCal is the resource calendar, and fldAdminCal is the calendar folder for the shared Admin mailbox. CleanUpTmpCalendars is a function that deletes any subfolders of fldAdminCal. (They are deleted to avoid a naming clash if the program didn't clean up after itself the last time the calendar program ran.) If the function completes successfully, it returns True.

I know fldConflCal and fldAdminCal are set properly in cache mode, because I see the dialog box showing the progress of the copy operation. As soon as the copy indicatator disappears, the program breaks on the line that attempts to change the name of the calendar, but only in cached mode. In online mode, the variable fldTmp is always set.
I don't know if this helps, but one other odd thing I noticed in cache mode is that both the resource calendar and the shared admin calendar are duplicated in the Calendar View navigation pane -- not as sometimes happens where the ost hasn't synched yet and you see a phantom that disappears after you click it -- but duplicated in a way that if you select the top copy, the bottom copy is automatically selected at the same time. This happens even if the .OST file is rebuilt from scratch, or Outlook is re-installed (which we also tried).

Try restarting outlook using with resetnavpane switch and see if it fixes the double names. i don't know if that will fix the vb problem but it looks like the code isn't finding the folder - which could be cause there are two.
Well, this was an interesting exercise. When I first ran Outlook with the /resetnavpane switch, Outlook crashed and couldn't restart until I turned off Microsoft Lync -- it looks like that program shares the OST file -- and deleted the OST file. After the .OST was rebuilt, I could open Outlook with the switch. That fixed the double entries, but, as you say, it didn't fix the problem of running the VBA program in cached mode.

Then the Exchange support person got back to me with the default profile name -- Outlook -- so I created a new profile with it, but that brought back the double entries in cached mode (not only in the Outlook profile, but in my other profile as well). I again ran it with /resetnavpane switch, which cleared the duplicates, but the VBA program still didn't work in cache mode. So I guess that kills the hard-coded path theory.

Then I discovered something else. Because there were updates to the calendar, I had to switch back to online mode to run the program, but when I switched back to cache mode to test the VBA program, the duplicates returned again. (Our Exchange support person was able to replicate this behavior with some of his folders, but he couldn't explain it. He said, though, that they were pointing to the same instance, which explains why the twin is automatically selected with the original; they're not really duplicates, just duplicate pointers.) But it looks like whenever the profiles are refreshed from the server, the duplicates return, so perhaps they exist somewhere on the server.

This reminded me of another thing that happened when we were trouble-shooting the problem orginally. (I experimented with a few combinations to see if we could somehow work with cached mode.) Normally, we used the "Use Cached Exchange Mode" setting under "Cached Exchange Mode Settings" (on the Advanced tab) together with the "Download shared folders" setting. But I tried de-selecting the "Download shared folders" option. Using this cache mode configuration, the VBA program was able to copy the calendar to the shared admin calendar folder successfully, but it failed later because it couldn't find other shared folders it needed. This led me to believe whatever was causing the problem for the copy function was getting downloaded from the server. I wasn't able to get any more information about it from our Exchange support people, though, so I let it go.

How does the VBA CopyTo function work? What's different about cache mode and online mode that would cause it to fail to see that the copy was successfully completed in one but not in the other?
There is something goofy with the navigation pane - you shouldn't get duplicates when you switch between online and offline. How are you switching -do you have an online and offline profile or do you disable online mode? I'm not sure if it makes a difference, but i would use two profiles.

Have you tried starting outlook with the resetnavpane switch in cached mode, then in online mode? This will insure that both the ost and the server have fresh navigation pane configuration data.

I think the duplicates are causing problem - the vba doesn't know which folder to use, it can't detect they are identical only that two exist.

The copy to function is not the problem, at least not on its own - you give it the to and from folders and it copies them. The problem is that it is having problems finding the folder you're telling it to use.
I've been changing the account settings on both profiles on the Exchange dialog box from Data File properties (either from the Control Panel (User Accounts > Mail) or from Outlook (File > Account Settings).


After reading your last post, I tried resetting both profiles with the /resetnavpane in both online and cached mode at least a half dozen times, and in cached mode, I waited until all the folders were up-to-date, but every time I switch from online back to cached mode, the duplicates reappear. (They are cleared on the second logon w/the reset.) I asked our Exchange support person to try it too in case I don't have sufficient privileges, and the result was the same.

But I don't see how this is causing the problem, because even after the duplicates are cleared through the second navpane reset, the copy function still fails in cached mode. There isn't a second copy to confuse it. Is there any other reason the copy function might fail?
You're copying to a different mailbox? How are you calling the folder? You might need to use GetFolderPath
Yes, the program uses a shared mailbox, accessible by me and my backup admins. Besides being a temporary holding area, it also contains folders related to subscriptions to the mobile calendar -- e.g., sharing invitations that contain the locations of the shared secondary calendar folders where the resource calendar is copied. (This allows people to use one constant mailbox for subscriptions, instead of individuals' mailboxes that could change.)

The target folder in the copyTo function is called through a global variable that is set in an initialization procedure when Outlook is started. I use the GetDefaultFolder function to set the global variable:

Set fldAdminCal = objStore.GetDefaultFolder(olFolderCalendar)". (The initialization procedure sets a few global variables; it loops through the object stores and then uses a case statement to set the variables that pertain to the object store. In this case, the shared admin mailbox, called "CARDS Admin". I did that because I have no way of knowing which folders would be in the backup admins' profiles.)

When the copy function failed, I checked both the resource calendar and the target folders to find out why, but both variables were set. This is what the target folder contained:


The path, \\CARDS Admin\Calendar is there. Since that's the path I'd enter into GetFolderPath, I don't see how using GetFolderPath would help.
We may have to give up on this application, since no one can figure out how to get it working again in cached mode.

I know resource calendars can be visible in OWA, since I've seen the offsite resource calendar on it, but are they also visible from the mobile phone app versions of OWA? Specifically, for iPhone, Android and Windows Mobile?

I've tried accessing OWA from my computer (which is behind a firewall) and I can see the resource calendar, but when I try accessing OWA on Safari from my personal iPhone, I can see only my personal calendars.
No, shared calendars aren't accessible in mobile apps - the user could use a browser and open OWA, but the email apps won't open a shared folder.
The path, \\CARDS Admin\Calendar is there. Since that's the path I'd enter into GetFolderPath, I don't see how using GetFolderPath would help.

I'm not 100% sure it will - but its designed to get the underlying data file path, which is required for outlook to know where the mailbox is (when its not in the default data file. When you use cached mode, the shared folder is in the default data file so it may not work.
Thanks for persisting.

OK, so it looks like we have no alternative. We either fix cached mode, or rewrite the program so it can run without intervention in online mode.

Something is definitely corrupted in cached mode that goes beyond the copy function. I created a new "TempHold" calendar folder in the shared mailbox to see if using a different folder name might solve the problem and if I could get its file path using your GetFolderPath function, but when I exited Outlook and restarted it in cached mode, the macro broke into the debugger in the initialization program that runs at startup, because this time a global variable hadn't been set. (The initialization program is the code I described earlier that loops through the datastores and assigns global variables to the folders I use.) I couldn't step through the program to find out why, though, because whenever I reached a next datastore line, VBA went into la-la land and reset itself, and when I started the procedure again, I could never get past the first datastore. (That explained why the global variable hadn't been set -- the loop never got to the datastore where the folder was located.)

Again, when I ran Oulook in online mode, the new folder posed no problem. (When I removed the new calendar folder and restored the VBA code to using the regular calendar folder, it broke at the copy function again in cached mode, as before -- i.e,. not at startup.)

How does cached mode look at folders? Why would creating a new calendar folder suddenly make it impossible to loop through datastores? Is the datafile stored on the server and downloaded to local machines in cached mode? Is it independent of profiles?

I ask because when our Exchange support person was troubleshooting this last month, he tried creating a new mailbox and copying all the folders the program needed from the shared mailbox into the new one. He also copied the VB code to his computer, and ran it using his login. VBA broke in cached mode at the copy function, just as it had for me.

If the datafile is the culprit, is there a way to fix it?
It's more likely an update broke it, not corruption in cache mode. Did you install any updates around that time? SP2 came out about that time frame, and several (buggy) security updates.

I think it will be worth checking in the MSDN forum at http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev - the devs that work those forums might know what's going on. Actually, I'll ask the MVPs who work that forum if they have any ideas, it might save you from reposting it.
The program was running under perfectly under Exchange 2010, SP2, rollup 3, for at least a month, and our Exchange support person says we hadn't made any software changes at the time the problem started (Oct. 9). Our company does alot of disaster recovery exercises in October, so we frequently got messages saying we had to reboot Outlook. In this case, the program had run earlier in the day. Towards the end of the day Outlook hung and I abended it. As I said, I wasn't able to restart it, so a tech support person created a new OST profile for me, which enabled me to start Outlook again the next day, but ever since then I couldn't run this application in cached mode. So the problem seems directly related to the forced shutdown. Anyway I will check the forum, as you suggested.

I appreciate your taking the time to help.

I ask because when our Exchange support person was troubleshooting this last month, he tried creating a new mailbox and copying all the folders the program needed from the shared mailbox into the new one. He also copied the VB code to his computer, and ran it using his login. VBA broke in cached mode at the copy function, just as it had for me.

Because of the above, it doesn't seem like the crash did it - unless its specifically the folder that is corrupted. But, you've tried making a new folder, correct?
A new mailbox, yes, but additional folders needed by the application were created by copying the old folders to it. (We keep subscriber information and sharing invitations in separate folders on the shared mailbox, and those folders were copied.)

If the folder weren't corrupted, why would duplicates appear in the Nav panes (for both calendars and tasks BTW) whenever we switched from online mode to cached mode, even though we had cleared them the last time we were in cached mode using the reset switches? That stuff had to be downloaded from the server, didn't it?

Should we try creating new folders for those items and then copy the items across? Would that make a difference?
I would try a new mailbox, new folders. See if it works. If so, move the contents of the old folders to the new mailbox.

Corrupt folders makes sense, but I'm surprised it worked in online mode.
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Outlook 2003 VBA Won't Run In Outlook 2010 Outlook VBA and Custom Forms 4
J VBA code (rules) won't work after reboot Outlook VBA and Custom Forms 2
T Outlook 365 won't take new working password Using Outlook 0
icacream New password won't update Using Outlook 2
Travis Lloyd Messages Won't Display In Outlook 2019 Home & Business Using Outlook 0
Paula S. Outlook 2013 won't recognize new password Using Outlook 4
C Why won't Title display in message list? Using Outlook 1
C Copy Move item won't work Outlook VBA and Custom Forms 2
GregS Outlook 2016 iPhone won't download Outlook 2016 Mail. Using Outlook 0
L Outlook Office 365 client: won't remember my setting File, not to collapse ribbon Using Outlook 2
M outlook won't open! Using Outlook 1
soadfan Outlook won't send e-mail when offline Outlook VBA and Custom Forms 19
M other user's mailbox won't open, forms disappeared Using Outlook 42
P Outlook 2016 won't Start Using Outlook 3
Phil52 Outlook won't work Using Outlook 1
N editing drafts - won't let me save Using Outlook 12
Diane Poremsky After viewing the Outbox, messages won't send Using Outlook 0
Diane Poremsky Rules & Alerts Dialog Won't Open Using Outlook 1
Diane Poremsky Outlook 2013: Control Panel Mail Won't Open Using Outlook 0
Diane Poremsky Outlook Links Won't Open In Windows 10 Using Outlook 1
L Outlook 2013 won't open MS Office attachments Using Outlook 1
Jaegel Email Hyperlinks from one source won't open Using Outlook 4
Diane Poremsky Excel Files Won't Display in Reading Pane Using Outlook 1
T Outlook 2010 calendar won't sync with Android phone Using Outlook 3
A iPhone Contacts in Outlook won't File As First, Last Using Outlook 0
JulieB Default data file won't change Using Outlook 6
B Restoring PST files won't work Using Outlook 1
J Outlook won't open. PST file busy. Using Outlook 3
P Outlook 2007 won't connect Using Outlook 6
S Outlook 2010 won't send on Windows 8 Using Outlook 2
R Outlook won't run except in Safe mode problem Using Outlook 5
M Outlook 2013/365 won't export 99% of my contacts to csv Using Outlook 2
K Macro won't consistently re-enable Outlook VBA and Custom Forms 2
B Add-in "always enabled" but Outlook 13 won't open Using Outlook 7
D Outlook 2013 Categories won't print In color Using Outlook 2
M Outlook 2013 won't convert Excel contacts into Outlook contacts using my custom form Using Outlook 3
V Custom form won't open for edit Outlook VBA and Custom Forms 3
C images won't display in email Using Outlook 2
J why won't the automatic send/receive work Using Outlook 7
B icloud calendar stopped syncing, won't restart Using Outlook 1
C Outlook 2010 Address Book, won't stay selected Using Outlook 5
D 2013 BCM Won't Install BCM (Business Contact Manager) 1
R Emails won't come into outlook but can send Using Outlook 0
A OL13 Calendar, won't allow entering 2 appointments consecutively Using Outlook 4
Z Outlook opens minimized, won't maximize Using Outlook 2
J Email won't send Automatically in Outlook 2010 Using Outlook 3
G Outlook 2013 won't download images Using Outlook 6
O Calender first day Sunday won't stay Using Outlook 3
B Outlook 2010 won't save 'current view' with reading pane at 'bottom' Using Outlook 4
E Outlook 2013 calendar won't sync with iphone 4s Using Outlook 14

Similar threads