A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Access Outlook from Word with VBA code



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 22nd 07, 09:49 AM posted to microsoft.public.outlook.program_vba
Simon Minder
external usenet poster
 
Posts: 11
Default Access Outlook from Word with VBA code

Hi all,

I have a problem with my template in 2007. I worte a template in 2003 with
VBA code behind. Everything works fine there, however, if I run this in 2007
the program stops at 'Set olApp = CreateObject("Outlook.Application")' (see
the whole code below). Are there any changes in VBA between 2003 and 2007? Or
why can I not create such an object?

Private Sub cmdSearchContact_Click()

Dim olApp As Outlook.Application
Dim objContact As Outlook.ContactItem
Dim objContacts As Outlook.MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Dim objAllContacts As Object

' Reset List
lstContacts.Clear


Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")

If optPersonalContacts = True Then
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)

ElseIf optMfoContacts = True Then
Set objContacts = objNameSpace.Folders("Public Folders"). _
Folders("All Public Folders"). _
Folders("MFO Contacts")
End If

Set objAllContacts = objContacts.Items

For Each objContact In objAllContacts
If objContact.FullName Like "*" & txtSearchContact & "*" Then
lstContacts.AddItem objContact.FullName
Else
' Do nothing
End If
Next
End Sub

Kind regards,

Simon Minder
  #2  
Old February 22nd 07, 03:12 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Access Outlook from Word with VBA code

There were no changes to VBA that would cause CreateObject not to work.
Possibilities are a security setting in Word not allowing code to run or
some script stopper in an A-V or software firewall preventing CreateObject
from working.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Simon Minder" wrote in message
news
Hi all,

I have a problem with my template in 2007. I worte a template in 2003 with
VBA code behind. Everything works fine there, however, if I run this in
2007
the program stops at 'Set olApp = CreateObject("Outlook.Application")'
(see
the whole code below). Are there any changes in VBA between 2003 and 2007?
Or
why can I not create such an object?

Private Sub cmdSearchContact_Click()

Dim olApp As Outlook.Application
Dim objContact As Outlook.ContactItem
Dim objContacts As Outlook.MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Dim objAllContacts As Object

' Reset List
lstContacts.Clear


Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")

If optPersonalContacts = True Then
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)

ElseIf optMfoContacts = True Then
Set objContacts = objNameSpace.Folders("Public Folders"). _
Folders("All Public Folders"). _
Folders("MFO Contacts")
End If

Set objAllContacts = objContacts.Items

For Each objContact In objAllContacts
If objContact.FullName Like "*" & txtSearchContact & "*" Then
lstContacts.AddItem objContact.FullName
Else
' Do nothing
End If
Next
End Sub

Kind regards,

Simon Minder


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access a custom control in an outlook form from my VBA code? MeAgin Outlook and VBA 1 January 23rd 07 05:39 AM
VBA code not starting on some Outlook 2003 clients, does on others. [email protected] Outlook and VBA 3 May 17th 06 05:21 PM
VBA Code to put in Access that will send an Email with Attachments [email protected] Outlook and VBA 1 April 9th 06 05:30 PM
Using VBA for Outlook and VBA for Access within Access Sardonic Outlook and VBA 1 March 17th 06 12:34 PM
Running query from Access Form commmand using VBA code Berny Outlook and VBA 4 January 16th 06 02:12 PM


All times are GMT +1. The time now is 04:56 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.