Mosher Outlook 2000 Code wont run in Outlook 2002 
Author Message
 Mosher Outlook 2000 Code wont run in Outlook 2002

Does anyone know why this Sue Mosher code crashes at the "Dim objExcel As
Excel.Application" on a system running Outlook 2002 and Excel2002? I get a
compile error User-Defined Type Not Defined. This code runs fine on my
Outlook 2000 system.

Sub DLToExcel()
    Dim objApp As Application
    Dim objDL As Object
    Dim objRecip As Recipient
    Dim objAddrEntry As AddressEntry
    Dim objExcel As Excel.Application
    Dim objWB As Excel.Workbook
    Dim objWS As Excel.Worksheet
    Dim objRange As Excel.Range
    Dim I As Integer
    Dim intRow As Integer
    Dim intStartRow As Integer
    Dim intCol As Integer

    Set objApp = CreateObject("Outlook.Application")
    If objApp.Inspectors.Count > 0 Then
        Set objDL = objApp.ActiveInspector.CurrentItem
        If objDL.Class <> olDistributionList Then
            MsgBox _
              "The current item is not a distribution list."
            GoTo Exit_DLToExcel
        End If
    Else
        MsgBox "No open item"
        GoTo Exit_DLToExcel
    End If

    On Error Resume Next
    Set objExcel = GetObject(, "Excel.Application")
    On Error GoTo 0
    If objExcel Is Nothing Then
        Set objExcel = CreateObject("Excel.Application")
    End If
    objExcel.Visible = True
    Set objWB = objExcel.Workbooks.Add
    Set objWS = objWB.Worksheets(1)

    'objWS.Cells(1, 1) = objDL.Subject
    intStartRow = 1
    intRow = intStartRow
    For I = 1 To objDL.MemberCount
        Set objAddrEntry = objDL.GetMember(I).AddressEntry
        objWS.Cells(intRow, 1) = objAddrEntry.Name
        objWS.Cells(intRow, 2) = objAddrEntry.Address
        objWS.Cells(intRow, 3) = objAddrEntry.Type
        objWS.Cells(intRow, 4) = objDL.Subject
        intRow = intRow + 1
    Next
    intRow = intRow - 1
    Set objRange = objWS.Range(Cells(3, 1), Cells(intRow, 3))
    For I = 1 To 3
        objRange.Columns(I).EntireColumn.AutoFit
    Next
    objWB.Names.Add _
        Name:=Replace(objDL.Subject, " ", ""), _
        RefersTo:="=" & "" & objWS.Name & _
        "!" & objRange.Address & ""
    objWS.Activate

Exit_DLToExcel:
    Set objApp = Nothing
    Set objDL = Nothing
    Set objRecip = Nothing
    Set objAddrEntry = Nothing
    Set objWB = Nothing
    Set objWS = Nothing
    Set objRange = Nothing
    Set objExcel = Nothing
End Sub



Mon, 27 Jun 2005 00:46:43 GMT  
 Mosher Outlook 2000 Code wont run in Outlook 2002
Sounds like you need to add a reference to Excel in your project -- Tools | References in VBA.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm
Quote:

> Does anyone know why this Sue Mosher code crashes at the "Dim objExcel As
> Excel.Application" on a system running Outlook 2002 and Excel2002? I get a
> compile error User-Defined Type Not Defined. This code runs fine on my
> Outlook 2000 system.



Mon, 27 Jun 2005 04:10:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Question for Sue Mosher on ViewHTML/Preview/Outlook 2002

2. Outlook Plugin - 2000 and 2002?

3. Outlook 2000 & 2002

4. Programming with Outlook 2002 / Windows 2000 possible?

5. folder userproperty - outlook 2000/2002

6. Always BCC in Outlook 2000/2002/XP

7. programmatically creating, modifying, or deleting Exchange 2000-based rules using VBA through Outlook 2002

8. GUI extension for Outlook 2000/2002 !

9. Project 2002 and Outlook 2000

10. Experts: Outlook 2000 / 2002 and VBScript

11. VB, OUTLOOK 2002 & 2000 and CRYSTAL REPORT

12. Does Word VBA 2002 developed code run on Word 2000

 

 
Powered by phpBB® Forum Software