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

Outlook macro abends but Word macro runs successfully



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 13th 06, 11:55 PM posted to microsoft.public.outlook.program_vba
Jreue
external usenet poster
 
Posts: 6
Default Outlook macro abends but Word macro runs successfully

I have created a macro for copying 140 contactitems. The macro was created
under Outlook 2003 (Vbaoject.OTM). When I run this macro, it successfully
copies around 125 rows and then abends. The Err.Description contains
"Automation Error, Unspecified Error". Then I run the same macro in the
debugger and set a breakpoint at the copy of row 125 to capture the error,
everything works fine and it continues to copy all 140 contactitems. As
another test, I created the exact same macro under a Word document and it
runs to completion. The code follows:

Option Explicit
Private ol As Object
Private olns As Object
Private AllItems As Object
Private Itm As Object

Private Sub CopyToButton_Click()

Dim myItem As Object
Dim i As Integer
Dim projectNameFrom, projectNameTo As String

On Error Resume Next

Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")

projectNameFrom = "James Test 5"
projectNameTo = "James Test 1"

i = 0

Set AllItems = olns.GetDefaultFolder(18).Folders("TBS
Applications").Folders("CRM").Folders("Event
Contacts").Items.Restrict("[Event Name] = """ & projectNameFrom & """")

For Each Itm In AllItems
i = i + 1

Set myItem = olns.GetDefaultFolder(18).Folders("TBS
Applications").Folders("CRM").Folders("Event Contacts").Items.Add

myItem.UserProperties.Find("Event Name") = projectNameTo
myItem.JobTitle = Itm.JobTitle
myItem.FullName = Itm.FullName
myItem.CompanyName = Itm.CompanyName
myItem.Email1Address = Itm.Email1Address
myItem.BusinessTelephoneNumber = Itm.BusinessTelephoneNumber
myItem.UserProperties.Find("Participation Status").Value = "Invited"
myItem.Save
If Err Then
MsgBox "failed on row: " + i
MsgBox Err.Description
Exit Sub
End If

Next

MsgBox "Done"

Set ol = Nothing
Set olns = Nothing
Set myItem = Nothing
Set AllItems = Nothing
Set Itm = Nothing

End Sub

The contactitems being copied are associated with a custom form.
Any ideas?
--
James
Ads
 




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
Call macro stored in Excel workbook from Outlook's macro Gvaram Outlook and VBA 5 October 4th 06 06:26 AM
Macro runs on startup jbc Outlook - Installation 1 September 20th 06 07:40 PM
Macro to search for word Dave Neve Outlook and VBA 7 July 26th 06 09:52 PM
Create a macro that runs from a Rule CF_business_analyst Outlook and VBA 8 January 13th 06 05:12 PM


All times are GMT +1. The time now is 11:26 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.