M
Marco B
Hello,
I looked around in several forums without to find anything about what
I'm trying to figure out since this morning. My problem ist hat I
would like to print labels via VB code from an Outlook.Selection of
Contacts. Everything works fine until this Outlook Contacts Selection
reaches the Number 250. For the rest of the selection Outlook
Selection returns an empty or invalid Contact item which results in an
Error (Err Number 13) like Type mismatch (I asume there is no Contact
Item really coming from this Selection.
Here some code:
Function generateDok(pcWordTemplate As String)
On Error GoTo ErrorHandler
Dim loFolder As MAPIFolder
Dim loItm As Object
Dim loExplorer As Explorer
Dim loSelection As Outlook.Selection
***
If Not m_olApp.ActiveExplorer Is Nothing Then
'Set a reference to the currently selected folder
Set loExplorer = m_olApp.ActiveExplorer
Set loFolder = loExplorer.CurrentFolder
***
Set loSelection = loExplorer.Selection
'Open Word invisibly
Set loAppWord = GetObject(, "Word.Application")
***
'Open a new letter based on the selected template
loAppWord.Documents.Add (lcWordTemplate)
For Each loItm In loSelection
If loItm.Class = olContact Then ‘ the 250th element is a
Contact object but loItm seems to contain nothing ??
'------------------------------------------------------------------------------
'Here on the 250th element the call raises the Error
loAppWord.Selection.TypeText (doAdresse(loItm,
pcWordTemplate))
'------------------------------------------------------------------------------
'Check row number before moving to the next cell
lvRow = loAppWord.Selection.Information(wdEndOfRangeRowNumber)
loAppWord.Selection.MoveRight Unit:=wdCell
'Check row number after moving to the next cell
lvNewRow =
loAppWord.Selection.Information(wdEndOfRangeRowNumber)
'If the cursor is still on the same row, go to the next
cell
If (lvRow = lvNewRow) Then
loAppWord.Selection.MoveRight Unit:=wdCell
End If
End If
Next
***
End If
***
ErrorHandlerExit:
Exit Function
ErrorHandler:
***
End Function
It does not depend if the contact folder is locally or in the public
folder. In both cases the application stops with the error. Has anyone
had such a behavior before and how can I resolve it?
I looked around in several forums without to find anything about what
I'm trying to figure out since this morning. My problem ist hat I
would like to print labels via VB code from an Outlook.Selection of
Contacts. Everything works fine until this Outlook Contacts Selection
reaches the Number 250. For the rest of the selection Outlook
Selection returns an empty or invalid Contact item which results in an
Error (Err Number 13) like Type mismatch (I asume there is no Contact
Item really coming from this Selection.
Here some code:
Function generateDok(pcWordTemplate As String)
On Error GoTo ErrorHandler
Dim loFolder As MAPIFolder
Dim loItm As Object
Dim loExplorer As Explorer
Dim loSelection As Outlook.Selection
***
If Not m_olApp.ActiveExplorer Is Nothing Then
'Set a reference to the currently selected folder
Set loExplorer = m_olApp.ActiveExplorer
Set loFolder = loExplorer.CurrentFolder
***
Set loSelection = loExplorer.Selection
'Open Word invisibly
Set loAppWord = GetObject(, "Word.Application")
***
'Open a new letter based on the selected template
loAppWord.Documents.Add (lcWordTemplate)
For Each loItm In loSelection
If loItm.Class = olContact Then ‘ the 250th element is a
Contact object but loItm seems to contain nothing ??
'------------------------------------------------------------------------------
'Here on the 250th element the call raises the Error
loAppWord.Selection.TypeText (doAdresse(loItm,
pcWordTemplate))
'------------------------------------------------------------------------------
'Check row number before moving to the next cell
lvRow = loAppWord.Selection.Information(wdEndOfRangeRowNumber)
loAppWord.Selection.MoveRight Unit:=wdCell
'Check row number after moving to the next cell
lvNewRow =
loAppWord.Selection.Information(wdEndOfRangeRowNumber)
'If the cursor is still on the same row, go to the next
cell
If (lvRow = lvNewRow) Then
loAppWord.Selection.MoveRight Unit:=wdCell
End If
End If
Next
***
End If
***
ErrorHandlerExit:
Exit Function
ErrorHandler:
***
End Function
It does not depend if the contact folder is locally or in the public
folder. In both cases the application stops with the error. Has anyone
had such a behavior before and how can I resolve it?