Using Clipboad in Outlook VBA

M

Michael

Hello to all

I using XP and Outlook 2003 and I like to copy selected mailadresses from
the current OL Explorer (contact items) to the clipboard. Problem: The
clipboad Object doesn't work. I don't know why.

Thank you for any hint!

Michael

Public Sub A_Mail2Clipboard()
'This Makro shall copy all emailaddresses from selected records of the
current OL Explorer

Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
Dim x As Integer
MsgTxt = ""
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
MsgTxt = MsgTxt & myOlSel.Item(x).Email1Address & ", "
Next x



clipboard.SetText MsgTxt '<-------- It looks like, the
clipboard is not available ?????


End Sub
 
M

Michael

Hi again.

Here are my final code: Maybe someone can use it too.

Thanks to all!

Michael



Dim MyData As DataObject

Public Sub A_Mail2Clipboard()
'This Makro copies all emailaddresses from selected records of the
current OL explorer

Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
Dim x As Integer
MsgTxt = ""
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
MsgTxt = MsgTxt & myOlSel.Item(x).Email1Address & ", "
Next x


Set MyData = New DataObject

MyData.SetText MsgTxt

MyData.PutInClipboard


End Sub
 
Joined
Jul 11, 2011
Messages
1
Reaction score
0
Hello Michael, So it's 6 years after your post and I just wanted to say "Thanks ... your code was exactly what I needed." I'm still using Outlook 2003 and it worked for me. I'm adding additional info just in case someone finds this in another 6 years. I use Outlook 2003 Contacts but Thunderbird email. Would like to be able to select multiple Outlook contacts and then Send an email to them - but Outlook only wants to send via Outlook. This code will help me select contacts. Copy them to clipboard, then just paste them in the Outlook "TO:" line. If someone has a better way, I'd be happy to hear it - but this extra step doesn't bother me -- it's a big improvement over what I used to do. ONE more piece of information: I had a compile error when creating the DataObject. This search solved the problem: I found the solution here: http://windowssecrets.com/forums/showthread.php/100385-DataObject-Compile-Error-(MSWord-2003) Best regards, William
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top