putInClipboard method errors on mac

S

subra

putInClipboard method of the DataObject is putting some invisible
characters on clipboard at the end of the string. I can see these
characters when i paste the clipboard conetents in BBedit. This
happens only on Mac (OSX). I don't have any problem on windows. I
figured out that for every character in the string one invisible
character is added at the end plus two ( if i have 10 character
string, there are 12 invisible characters). Also when I use GetText I
don't get anything. Following is my test code. I appreciate any
suggestions.

Dim data As DataObject
Dim text, rs As String

For i = 1 To 100 Step 1
text = text & "hello"
Next

Set data = New DataObject
data.SetText text
data.PutInClipboard

data.GetFromClipboard
rs = data.GetText
' no text in my immediate window
Debug.Print rs
 
J

J.E. McGimpsey

putInClipboard method of the DataObject is putting some invisible
characters on clipboard at the end of the string. I can see these
characters when i paste the clipboard conetents in BBedit. This
happens only on Mac (OSX). I don't have any problem on windows. I
figured out that for every character in the string one invisible
character is added at the end plus two ( if i have 10 character
string, there are 12 invisible characters). Also when I use GetText I
don't get anything. Following is my test code. I appreciate any
suggestions.

Dim data As DataObject
Dim text, rs As String

For i = 1 To 100 Step 1
text = text & "hello"
Next

Set data = New DataObject
data.SetText text
data.PutInClipboard

data.GetFromClipboard
rs = data.GetText
' no text in my immediate window
Debug.Print rs

I can reproduce your results in PutInClipboard, except that I get
the invisible characters plus one extra character, not two (all
Unicode 255). I don't know if this has been bugged before, but I'll
submit it. Please do likewise, using XLv.X's Help/Send Feedback
feature.

AFAIK, the GetText problem's been a bug in MacXL since XL98. I know
that I and others have reported the problem, so perhaps the next
version...

In the mean time, the best workaround I've found is to paste the
contents of the clipboard into a cell in a new workbook, read it
into a string variable, then delete that workbook.

Depending on what you're doing, of course, you may not need to. The
Mac clipboard is persistent - Application.CutCopyMode = False does
not clear it - so you may not need to read it into a dataobject at
all.

For a macro that *does* clear the Mac clipboard, see

http://www.mcgimpsey.com/excel/clearclipboard.html
 
S

subra

Thanks for your suggestion. I am not bothered whether clipboard is
cleared or not. For my purpose, I need to get data from a selection
and modify it in a format I wanted and put it in the clipboard so that
another application can take that data. There is no other way for me
to pass that data to that application. This bug occurs only on Mac OSX
excel and it is fine on Mac OS9 and on Windows. I think the problem is
in "putInClipboard method of DataObject. If I just copy with short cut
keys (or from menu) and pasting into BBEdit i don't see any extra
characters.
 
J

J.E. McGimpsey

Thanks for your suggestion. I am not bothered whether clipboard is
cleared or not. For my purpose, I need to get data from a selection
and modify it in a format I wanted and put it in the clipboard so that
another application can take that data. There is no other way for me
to pass that data to that application. This bug occurs only on Mac OSX
excel and it is fine on Mac OS9 and on Windows. I think the problem is
in "putInClipboard method of DataObject. If I just copy with short cut
keys (or from menu) and pasting into BBEdit i don't see any extra
characters.

I agree, and I've submitted a detailed bug report.

I'm curious as to why you can't use copy to read even a modified
text into the Clipboard. I've done that frequently for passing to
other apps. While I've occasionally used dataobjects, I've very
rarely had the need.

I've also been successful before using Applescript and conditionally
compiled the code for Win (no applescript) and Mac (applescript).
 

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