
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