# outlook vba works in break mode only

**URL:** <https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346>\
**Category:** Factual Questions\
**Created:** [August 3, 2011, 6:10pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346 "2011-08-03T18:10:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Don\_t\_Call\_Me\_Shirley](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Don\_t\_Call\_Me\_Shirley](https://boards.straightdope.com/u/Don_t_Call_Me_Shirley)\
**Post date:** [August 3, 2011, 6:10pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/1 "2011-08-03T18:10:14Z")

</div>

I have a macro that I run in Outlook. All it needs to do is open a Word document. It opens Word but won’t open the document. But when I step through one line at a time in break mode, it works fine. Here is the relevant part of the code:

Set Word = Application.CreateObject(“Word.Application”)  
Word.Visible = True  
Word.Documents.Open (“P:\TPS\Dave\checklist.doc”)

Should be simple enough. But when the macro is running it opens Word but not the document. Any ideas?

---

<div class="post-metadata">

**Author:** ![CookingWithGas](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cookingwithgas/32/485_2.png) [@CookingWithGas](https://boards.straightdope.com/u/CookingWithGas)\
**Post date:** [August 3, 2011, 6:18pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/2 "2011-08-03T18:18:21Z")

</div>

I have done a lot of VBA in Outlook, Excel, Word, and Project. I have never seen any macro that does not run properly unless you F8 it, so I’m not sure what is causing this.

Just from this snippet what jumps out at me is that you are using Word as an object name. I would recommend you use something else, like WordApp or something. You could be having a reserved word collision or something more subtle.

I don’t know if that is causing your problem but it’s so easy to change I would try it.

---

<div class="post-metadata">

**Author:** ![Don\_t\_Call\_Me\_Shirley](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Don\_t\_Call\_Me\_Shirley](https://boards.straightdope.com/u/Don_t_Call_Me_Shirley)\
**Post date:** [August 3, 2011, 6:27pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/3 "2011-08-03T18:27:21Z")

</div>

> [@CookingWithGas](#):
>
> I have done a lot of VBA in Outlook, Excel, Word, and Project. I have never seen any macro that does not run properly unless you F8 it, so I’m not sure what is causing this.
> 
> Just from this snippet what jumps out at me is that you are using Word as an object name. I would recommend you use something else, like WordApp or something. You could be having a reserved word collision or something more subtle.
> 
> I don’t know if that is causing your problem but it’s so easy to change I would try it.

Nope, that didn’t help. I’ve actually been running this macro for quite a while in Windows XP with no problems, but this morning I was moved to a Virtual Desktop running Windows 7. Maybe that has something to do with it?

---

<div class="post-metadata">

**Author:** ![CookingWithGas](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cookingwithgas/32/485_2.png) [@CookingWithGas](https://boards.straightdope.com/u/CookingWithGas)\
**Post date:** [August 3, 2011, 6:49pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/4 "2011-08-03T18:49:02Z")

</div>

I use XP and Vista, so I’m not sure why there might be an issue in W7. Another thing that occurred to me is that your document object is anonymous. You might try something like this

Dim d as Document  
Set Word = Application.CreateObject(“Word.Application”)  
Word.Visible = True  
Set d = Word.Documents.Open (“P:\TPS\Dave\checklist.doc”)

It shouldn’t be necessary, but I don’t really know what the problem is.

---

<div class="post-metadata">

**Author:** ![Don\_t\_Call\_Me\_Shirley](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Don\_t\_Call\_Me\_Shirley](https://boards.straightdope.com/u/Don_t_Call_Me_Shirley)\
**Post date:** [August 3, 2011, 7:16pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/5 "2011-08-03T19:16:39Z")

</div>

> [@CookingWithGas](#):
>
> I use XP and Vista, so I’m not sure why there might be an issue in W7. Another thing that occurred to me is that your document object is anonymous. You might try something like this
> 
> Dim d as Document  
> Set Word = Application.CreateObject(“Word.Application”)  
> Word.Visible = True  
> Set d = Word.Documents.Open (“P:\TPS\Dave\checklist.doc”)
> 
> It shouldn’t be necessary, but I don’t really know what the problem is.

That gives a compile error. It doesn’t recognize “Document” as a dimension type; remember this macro is in Outlook, not Word.

Thanks for your help. This is truly bizarre.

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [August 3, 2011, 7:19pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/6 "2011-08-03T19:19:41Z")

</div>

Maybe you should try running it with [UAC off](http://windows.microsoft.com/en-US/windows-vista/Turn-User-Account-Control-on-or-off), just to eliminate that as a roadblock.

---

<div class="post-metadata">

**Author:** ![CookingWithGas](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cookingwithgas/32/485_2.png) [@CookingWithGas](https://boards.straightdope.com/u/CookingWithGas)\
**Post date:** [August 3, 2011, 9:54pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/7 "2011-08-03T21:54:02Z")

</div>

> [@Don\_t\_Call\_Me\_Shirley](#):
>
> That gives a compile error. It doesn’t recognize “Document” as a dimension type; remember this macro is in Outlook, not Word.

You mean you don’t have the Word object reference library imported? That could also be a little glitch. But still doesn’t explain why your code works only in the debugger.

---

<div class="post-metadata">

**Author:** ![doubled](https://avatars.discourse-cdn.com/v4/letter/d/51bf81/32.png) [@doubled](https://boards.straightdope.com/u/doubled)\
**Post date:** [August 4, 2011, 2:28am UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/8 "2011-08-04T02:28:02Z")

</div>

> [@Don\_t\_Call\_Me\_Shirley](#):
>
> I have a macro that I run in Outlook. All it needs to do is open a Word document. It opens Word but won’t open the document. But when I step through one line at a time in break mode, it works fine. Here is the relevant part of the code:
> 
> Set Word = Application.CreateObject(“Word.Application”)  
> Word.Visible = True  
> Word.Documents.Open (“P:\TPS\Dave\checklist.doc”)
> 
> Should be simple enough. But when the macro is running it opens Word but not the document. Any ideas?

Wow, I was the developer at Microsoft who wrote the VBA integration into Outlook 10 years ago. Honestly, you are the first person I’ve ever encountered who actually used the feature. 🙂

Your code appears to be correct, and the fact that it works when you step one line at a time in break mode is suspicious. Just a guess – do you have some add-ins or startup macros in Word (not Outlook, but word)? Word is initialized in two phases – phase one starts the app, and phase two loads up all your add-ins. If you have a slow-loading plugin, then could cause phase two to take longer than usual. Loading the document during that time will fail. But your macro works when you step line-by-line, because then you’re going slower, so Word has enough time to finish loading its plugins and startup macros before you get to the last line which loads the document.

Try disabling your word addins and startup macros. Does that fix it then?

---

<div class="post-metadata">

**Author:** ![CookingWithGas](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cookingwithgas/32/485_2.png) [@CookingWithGas](https://boards.straightdope.com/u/CookingWithGas)\
**Post date:** [August 4, 2011, 10:19am UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/9 "2011-08-04T10:19:01Z")

</div>

> [@doubled](#):
>
> Wow, I was the developer at Microsoft who wrote the VBA integration into Outlook 10 years ago.

Seriously? That makes you practically a celebrity 🙂 So maybe \*you \*can tell me. Why doesn’t Outlook have a macro recorder? There are actually a lot of people who use this feature and that would have made life a lot easier. Outlook’s object model is not quite as intuitive as the Excel model, for example.

---

<div class="post-metadata">

**Author:** ![Don\_t\_Call\_Me\_Shirley](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Don\_t\_Call\_Me\_Shirley](https://boards.straightdope.com/u/Don_t_Call_Me_Shirley)\
**Post date:** [August 4, 2011, 12:11pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/10 "2011-08-04T12:11:58Z")

</div>

> [@doubled](#):
>
> Wow, I was the developer at Microsoft who wrote the VBA integration into Outlook 10 years ago. Honestly, you are the first person I’ve ever encountered who actually used the feature. 🙂
> 
> Your code appears to be correct, and the fact that it works when you step one line at a time in break mode is suspicious. Just a guess – do you have some add-ins or startup macros in Word (not Outlook, but word)? Word is initialized in two phases – phase one starts the app, and phase two loads up all your add-ins. If you have a slow-loading plugin, then could cause phase two to take longer than usual. Loading the document during that time will fail. But your macro works when you step line-by-line, because then you’re going slower, so Word has enough time to finish loading its plugins and startup macros before you get to the last line which loads the document.
> 
> Try disabling your word addins and startup macros. Does that fix it then?

I just had one add-in, a global template. I disabled it and it still didn’t work. I wrote a 3 second delay timer into the macro and now it works.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Don\_t\_Call\_Me\_Shirley](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Don\_t\_Call\_Me\_Shirley](https://boards.straightdope.com/u/Don_t_Call_Me_Shirley)\
**Post date:** [August 4, 2011, 12:13pm UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/11 "2011-08-04T12:13:06Z")

</div>

> [@CookingWithGas](#):
>
> Why doesn’t Outlook have a macro recorder?

This. +1000

---

<div class="post-metadata">

**Author:** ![Don\_t\_Call\_Me\_Shirley](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Don\_t\_Call\_Me\_Shirley](https://boards.straightdope.com/u/Don_t_Call_Me_Shirley)\
**Post date:** [August 9, 2011, 12:34am UTC](https://boards.straightdope.com/t/outlook-vba-works-in-break-mode-only/591346/12 "2011-08-09T00:34:22Z")

</div>

> [@doubled](#):
>
> Wow, I was the developer at Microsoft who wrote the VBA integration into Outlook 10 years ago. Honestly, you are the first person I’ve ever encountered who actually used the feature. 🙂
> 
> Your code appears to be correct, and the fact that it works when you step one line at a time in break mode is suspicious. Just a guess – do you have some add-ins or startup macros in Word (not Outlook, but word)? Word is initialized in two phases – phase one starts the app, and phase two loads up all your add-ins. If you have a slow-loading plugin, then could cause phase two to take longer than usual. Loading the document during that time will fail. But your macro works when you step line-by-line, because then you’re going slower, so Word has enough time to finish loading its plugins and startup macros before you get to the last line which loads the document.
> 
> Try disabling your word addins and startup macros. Does that fix it then?

Follow up question: is it possible to run my macro with an appointment selected, and have it pass the date and time of the appointment to a userform in the Word document?
