Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50271

[SOLVED] Copy and Pasting Data from Excel into External Programs - Quotes being added?

$
0
0
Good afternoon,

I have a strange little problem. I created a macro button to copy a cell's text for me so I can transfer it to another program (in this case a web-based program, but the same problem occurs with Notepad) it adds quotes and extraneous spaces to the output.

If I click the cell manually and select the text by hand and then copy, it pastes just fine. I'm copying out of a merged cell, if that matters.

Any thoughts?

Thanks so much!!

I don't think it's necessary, but here's my code. There is probably a more succinct way to do this, but my issue is the output, not the speed.

Code:

Sub CopyAnswer()

ButtonRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
ButtonColumn = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Column

questionrow = ButtonRow
questioncolumn = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", ButtonColumn + 2, 1)

'this has trouble with the merged cells so it gives me quotes
'need to make number of merged cells consistent, or find or way of finding how many rows there are
ActiveSheet.Range(questioncolumn & questionrow).Copy

Application.CutCopyMode = False

End Sub



---------- Post added at 02:27 PM ---------- Previous post was at 02:23 PM ----------

Apparently all I needed to do was ask before I came across a solution. But at least now it'll be online for others, I guess.

Here's what worked:

Code:

Sub CopyAnswer()

ButtonRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
ButtonColumn = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Column

questionrow = ButtonRow
questioncolumn = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", ButtonColumn + 2, 1)
questioncolumnend = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", ButtonColumn + 12, 1)


Dim answertext As String
answertext = ActiveSheet.Range(questioncolumn & questionrow).Text
'
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText answertext
clipboard.PutInClipboard

Application.CutCopyMode = False

End Sub

Thanks!

Viewing all articles
Browse latest Browse all 50271

Latest Images

Trending Articles



Latest Images