![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]() 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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |