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

Export members of distribution list



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 24th 07, 10:40 PM posted to microsoft.public.outlook.program_vba
Kees van Amerongen[_2_]
external usenet poster
 
Posts: 2
Default Export members of distribution list

I'm trying to get a list with the members of the distribution list from
Outlook 2003.



If found a macro on the internet that gives however the following error



Error: Objectvariabele or blockvariabele With is not assigned Error #91



Can anybody help me to correct this macro?







The macro is :



Public Sub DLToWord()
'This macro requires project references to the Outlook
'and Word object models.
Dim objOutlook As Outlook.Application
Dim objExplorer As Outlook.Explorer
Dim objSelection As Outlook.Selection
Dim objDL As Outlook.DistListItem
Dim objRecipient As Outlook.Recipient

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objTable As Word.Table
Dim objRange As Word.Range

Dim lngCount As Long
Dim lngIndex As Long
Dim strName As String
Dim strAddress As String
Dim strListName As String

On Error GoTo ErrorHandler

Set objOutlook = CreateObject("Outlook.Application")

'Get the currently active folder window.
Set objExplorer = objOutlook.ActiveExplorer

'Get the selected item(s) in that folder.
Set objSelection = objExplorer.Selection

'Look for 1 distribution list item to be selected.
If (objSelection.Count = 1) And (objSelection.Item(1).Class =
olDistributionList) Then

'Get the selection.
Set objDL = objSelection.Item(1)

'Get the name of the distribution list.
strListName = objDL.DLName

'Go to next line if there is an error.
On Error Resume Next

'See if Word is already open.
Set objWord = GetObject(, "Word.Application")

'If not, create a new Word application object.
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If

'Now back to the normal error handler.
On Error GoTo ErrorHandler

'Add a new document to Word and activate it.
Set objDoc = objWord.Documents.Add
objDoc.Activate

'Set the active range to the document start.
Set objRange = objDoc.Range(0, 0)

'See how many items are in the distribution list.
lngCount = objDL.MemberCount

'Add a Word table, with 1 more row than list members,
'use the first row for the list name. Table has 2 columns.
Set objTable = objDoc.Tables.Add(objRange, lngCount + 1, 2)

'Use With to make the code faster.
With objTable
'Insert the list name in the first row, first column.
objTable.Cell(1, 1).Range.InsertAfter strListName

'Make the list name bold face.
.Cell(1, 1).Range.Bold = True

'Now loop through the members of the list.
For lngIndex = 1 To lngCount
'Get a list member
Set objRecipient = objDL.GetMember(lngIndex)

'Get the name of the list member.
strName = objRecipient.Name

'Get the e-mail address of the list member.
strAddress = objRecipient.Address

'Insert the name and e-mail address.
.Cell(lngIndex + 1, 1).Range.InsertAfter strName
.Cell(lngIndex + 1, 2).Range.InsertAfter strAddress
Next lngIndex
.Columns.AutoFit
End With

'Move the cursor to the end of the document.
objWord.Selection.HomeKey Unit:=wdStory, Extend:=wdMove

'Make the document visible.
objWord.Visible = True
objDoc.ActiveWindow.Visible = True
Else
MsgBox "Not a Distribution List or more than 1 item is selected"
End If

MacroExit:
Set objOutlook = Nothing
Set objExplorer = Nothing
Set objSelection = Nothing
Set objDL = Nothing
Set objRecipient = Nothing

Set objWord = Nothing
Set objDoc = Nothing
Set objTable = Nothing
Set objRange = Nothing

Exit Sub

ErrorHandler:
MsgBox "Error: " & Err.Description & vbCrLf & "Error # " _
& Err.Number

Err.Clear
GoTo MacroExit
End Sub




  #2  
Old July 24th 07, 10:47 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Export members of distribution list

Show the code statement that raises the error.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Kees van Amerongen" wrote in message ...
I'm trying to get a list with the members of the distribution list from
Outlook 2003.



If found a macro on the internet that gives however the following error



Error: Objectvariabele or blockvariabele With is not assigned Error #91



Can anybody help me to correct this macro?







The macro is :



Public Sub DLToWord()
'This macro requires project references to the Outlook
'and Word object models.
Dim objOutlook As Outlook.Application
Dim objExplorer As Outlook.Explorer
Dim objSelection As Outlook.Selection
Dim objDL As Outlook.DistListItem
Dim objRecipient As Outlook.Recipient

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objTable As Word.Table
Dim objRange As Word.Range

Dim lngCount As Long
Dim lngIndex As Long
Dim strName As String
Dim strAddress As String
Dim strListName As String

On Error GoTo ErrorHandler

Set objOutlook = CreateObject("Outlook.Application")

'Get the currently active folder window.
Set objExplorer = objOutlook.ActiveExplorer

'Get the selected item(s) in that folder.
Set objSelection = objExplorer.Selection

'Look for 1 distribution list item to be selected.
If (objSelection.Count = 1) And (objSelection.Item(1).Class =
olDistributionList) Then

'Get the selection.
Set objDL = objSelection.Item(1)

'Get the name of the distribution list.
strListName = objDL.DLName

'Go to next line if there is an error.
On Error Resume Next

'See if Word is already open.
Set objWord = GetObject(, "Word.Application")

'If not, create a new Word application object.
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If

'Now back to the normal error handler.
On Error GoTo ErrorHandler

'Add a new document to Word and activate it.
Set objDoc = objWord.Documents.Add
objDoc.Activate

'Set the active range to the document start.
Set objRange = objDoc.Range(0, 0)

'See how many items are in the distribution list.
lngCount = objDL.MemberCount

'Add a Word table, with 1 more row than list members,
'use the first row for the list name. Table has 2 columns.
Set objTable = objDoc.Tables.Add(objRange, lngCount + 1, 2)

'Use With to make the code faster.
With objTable
'Insert the list name in the first row, first column.
objTable.Cell(1, 1).Range.InsertAfter strListName

'Make the list name bold face.
.Cell(1, 1).Range.Bold = True

'Now loop through the members of the list.
For lngIndex = 1 To lngCount
'Get a list member
Set objRecipient = objDL.GetMember(lngIndex)

'Get the name of the list member.
strName = objRecipient.Name

'Get the e-mail address of the list member.
strAddress = objRecipient.Address

'Insert the name and e-mail address.
.Cell(lngIndex + 1, 1).Range.InsertAfter strName
.Cell(lngIndex + 1, 2).Range.InsertAfter strAddress
Next lngIndex
.Columns.AutoFit
End With

'Move the cursor to the end of the document.
objWord.Selection.HomeKey Unit:=wdStory, Extend:=wdMove

'Make the document visible.
objWord.Visible = True
objDoc.ActiveWindow.Visible = True
Else
MsgBox "Not a Distribution List or more than 1 item is selected"
End If

MacroExit:
Set objOutlook = Nothing
Set objExplorer = Nothing
Set objSelection = Nothing
Set objDL = Nothing
Set objRecipient = Nothing

Set objWord = Nothing
Set objDoc = Nothing
Set objTable = Nothing
Set objRange = Nothing

Exit Sub

ErrorHandler:
MsgBox "Error: " & Err.Description & vbCrLf & "Error # " _
& Err.Number

Err.Clear
GoTo MacroExit
End Sub




  #3  
Old July 25th 07, 08:08 AM posted to microsoft.public.outlook.program_vba
Kees van Amerongen[_2_]
external usenet poster
 
Posts: 2
Default Export members of distribution list


Set objSelection = objExplorer.Selection


"Sue Mosher [MVP-Outlook]" schreef in bericht
...
Show the code statement that raises the error.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Kees van Amerongen" wrote in
message ...
I'm trying to get a list with the members of the distribution list from
Outlook 2003.



If found a macro on the internet that gives however the following error



Error: Objectvariabele or blockvariabele With is not assigned Error
#91



Can anybody help me to correct this macro?







The macro is :



Public Sub DLToWord()
'This macro requires project references to the Outlook
'and Word object models.
Dim objOutlook As Outlook.Application
Dim objExplorer As Outlook.Explorer
Dim objSelection As Outlook.Selection
Dim objDL As Outlook.DistListItem
Dim objRecipient As Outlook.Recipient

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objTable As Word.Table
Dim objRange As Word.Range

Dim lngCount As Long
Dim lngIndex As Long
Dim strName As String
Dim strAddress As String
Dim strListName As String

On Error GoTo ErrorHandler

Set objOutlook = CreateObject("Outlook.Application")

'Get the currently active folder window.
Set objExplorer = objOutlook.ActiveExplorer

'Get the selected item(s) in that folder.
Set objSelection = objExplorer.Selection

'Look for 1 distribution list item to be selected.
If (objSelection.Count = 1) And (objSelection.Item(1).Class =
olDistributionList) Then

'Get the selection.
Set objDL = objSelection.Item(1)

'Get the name of the distribution list.
strListName = objDL.DLName

'Go to next line if there is an error.
On Error Resume Next

'See if Word is already open.
Set objWord = GetObject(, "Word.Application")

'If not, create a new Word application object.
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If

'Now back to the normal error handler.
On Error GoTo ErrorHandler

'Add a new document to Word and activate it.
Set objDoc = objWord.Documents.Add
objDoc.Activate

'Set the active range to the document start.
Set objRange = objDoc.Range(0, 0)

'See how many items are in the distribution list.
lngCount = objDL.MemberCount

'Add a Word table, with 1 more row than list members,
'use the first row for the list name. Table has 2 columns.
Set objTable = objDoc.Tables.Add(objRange, lngCount + 1, 2)

'Use With to make the code faster.
With objTable
'Insert the list name in the first row, first column.
objTable.Cell(1, 1).Range.InsertAfter strListName

'Make the list name bold face.
.Cell(1, 1).Range.Bold = True

'Now loop through the members of the list.
For lngIndex = 1 To lngCount
'Get a list member
Set objRecipient = objDL.GetMember(lngIndex)

'Get the name of the list member.
strName = objRecipient.Name

'Get the e-mail address of the list member.
strAddress = objRecipient.Address

'Insert the name and e-mail address.
.Cell(lngIndex + 1, 1).Range.InsertAfter strName
.Cell(lngIndex + 1, 2).Range.InsertAfter strAddress
Next lngIndex
.Columns.AutoFit
End With

'Move the cursor to the end of the document.
objWord.Selection.HomeKey Unit:=wdStory, Extend:=wdMove

'Make the document visible.
objWord.Visible = True
objDoc.ActiveWindow.Visible = True
Else
MsgBox "Not a Distribution List or more than 1 item is selected"
End If

MacroExit:
Set objOutlook = Nothing
Set objExplorer = Nothing
Set objSelection = Nothing
Set objDL = Nothing
Set objRecipient = Nothing

Set objWord = Nothing
Set objDoc = Nothing
Set objTable = Nothing
Set objRange = Nothing

Exit Sub

ErrorHandler:
MsgBox "Error: " & Err.Description & vbCrLf & "Error # " _
& Err.Number

Err.Clear
GoTo MacroExit
End Sub






  #4  
Old July 25th 07, 01:17 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Export members of distribution list

The symptoms suggest that Outlook is not displaying an Explorer window, a window where the use can make a selection.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Kees van Amerongen" wrote in message ...

Set objSelection = objExplorer.Selection


"Sue Mosher [MVP-Outlook]" schreef in bericht
...
Show the code statement that raises the error.

"Kees van Amerongen" wrote in
message ...
I'm trying to get a list with the members of the distribution list from
Outlook 2003.

If found a macro on the internet that gives however the following error

Error: Objectvariabele or blockvariabele With is not assigned Error
#91

Can anybody help me to correct this macro?

The macro is :

Public Sub DLToWord()
'This macro requires project references to the Outlook
'and Word object models.
Dim objOutlook As Outlook.Application
Dim objExplorer As Outlook.Explorer
Dim objSelection As Outlook.Selection
Dim objDL As Outlook.DistListItem
Dim objRecipient As Outlook.Recipient

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objTable As Word.Table
Dim objRange As Word.Range

Dim lngCount As Long
Dim lngIndex As Long
Dim strName As String
Dim strAddress As String
Dim strListName As String

On Error GoTo ErrorHandler

Set objOutlook = CreateObject("Outlook.Application")

'Get the currently active folder window.
Set objExplorer = objOutlook.ActiveExplorer

'Get the selected item(s) in that folder.
Set objSelection = objExplorer.Selection

'Look for 1 distribution list item to be selected.
If (objSelection.Count = 1) And (objSelection.Item(1).Class =
olDistributionList) Then

'Get the selection.
Set objDL = objSelection.Item(1)

'Get the name of the distribution list.
strListName = objDL.DLName

'Go to next line if there is an error.
On Error Resume Next

'See if Word is already open.
Set objWord = GetObject(, "Word.Application")

'If not, create a new Word application object.
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If

'Now back to the normal error handler.
On Error GoTo ErrorHandler

'Add a new document to Word and activate it.
Set objDoc = objWord.Documents.Add
objDoc.Activate

'Set the active range to the document start.
Set objRange = objDoc.Range(0, 0)

'See how many items are in the distribution list.
lngCount = objDL.MemberCount

'Add a Word table, with 1 more row than list members,
'use the first row for the list name. Table has 2 columns.
Set objTable = objDoc.Tables.Add(objRange, lngCount + 1, 2)

'Use With to make the code faster.
With objTable
'Insert the list name in the first row, first column.
objTable.Cell(1, 1).Range.InsertAfter strListName

'Make the list name bold face.
.Cell(1, 1).Range.Bold = True

'Now loop through the members of the list.
For lngIndex = 1 To lngCount
'Get a list member
Set objRecipient = objDL.GetMember(lngIndex)

'Get the name of the list member.
strName = objRecipient.Name

'Get the e-mail address of the list member.
strAddress = objRecipient.Address

'Insert the name and e-mail address.
.Cell(lngIndex + 1, 1).Range.InsertAfter strName
.Cell(lngIndex + 1, 2).Range.InsertAfter strAddress
Next lngIndex
.Columns.AutoFit
End With

'Move the cursor to the end of the document.
objWord.Selection.HomeKey Unit:=wdStory, Extend:=wdMove

'Make the document visible.
objWord.Visible = True
objDoc.ActiveWindow.Visible = True
Else
MsgBox "Not a Distribution List or more than 1 item is selected"
End If

MacroExit:
Set objOutlook = Nothing
Set objExplorer = Nothing
Set objSelection = Nothing
Set objDL = Nothing
Set objRecipient = Nothing

Set objWord = Nothing
Set objDoc = Nothing
Set objTable = Nothing
Set objRange = Nothing

Exit Sub

ErrorHandler:
MsgBox "Error: " & Err.Description & vbCrLf & "Error # " _
& Err.Number

Err.Clear
GoTo MacroExit
End Sub






 




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
can the members of distribution list be hidden? DumbCluck Outlook - Using Contacts 1 April 11th 07 04:39 PM
Exporting Members on a distribution list WooYing Outlook - General Queries 3 September 29th 06 07:08 AM
Exporting Members on a distribution list WooYing Outlook - Using Contacts 3 September 29th 06 07:08 AM
members missing from distribution list EZim Outlook - Using Contacts 0 March 20th 06 06:04 PM
Adding Members to a Distribution List DeeW Outlook - Using Contacts 2 January 24th 06 09:20 PM


All times are GMT +1. The time now is 09:22 AM.


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.