0

I added VBA code to ThisOutlookSession to put a mail's subject line and the recipient's name into the mail body. This does not work reliably.

To be variable on where I paste the text, I use a data object of MSforms and it's PutInClipboard function to move the generated text to the Windows clipboard.

This works most of the time but sometimes the clipboard only contains two undefined characters. I am sure the text to be inserted was generated correctly.

// forClip is a string that contains a text line
Set MyData = New MSForms.DataObject
MyData.Clear
MyData.SetText forClip
MyData.PutInClipboard
// the code ended here but as described the clipboard then contains ��
// I added the following lines only to find out where it all goes wrong

MyData.GetFromClipboard
forClip = MyData.GetText(1) 
// the string going back to "forClip" only contains the two characters mentioned.

Set MyData = Nothing

The code works most of the time - but if it fails, it will keep failing.

Could it be, that the clipboard interprets the text not as text but as something different? Is there a way to force it to interpret the data as text?

Community
  • 1
  • 1
BeeJayF
  • 133
  • 2
  • 9
  • I've had problems with that code on Windows 10 - you may need to switch to an API-based method. See https://stackoverflow.com/questions/18668928/excel-2013-64-bit-vba-clipboard-api-doesnt-work – Tim Williams Nov 12 '19 at 16:02
  • Thank you @TimWilliams - this worked very well! – BeeJayF Nov 12 '19 at 17:01

0 Answers0