Copy from Excel and Paste in external app?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
482
Office Version
  1. 365
Platform
  1. Windows
Good morning!

Here's today's issue: I'm copying from a cell in Excel to another app. I'm getting a trailing carriage return when I paste in Notepad, Word, and Adobe Acrobat.

copy.png


Result:

paste.png


If I copy the text D10 and paste it in E10 I can get the value up in the Formula Bar. If I copy the text in the Formula Bar I can paste it anywhere without the trailing carriage return. Is it possible to copy the formula using VBA?

copy2.png
 
Do you have the code in the ShippingInstructions worksheet code?
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hello jmpatrick
if you run this code against the E10 cell does the immediate window indicate any 'extra' character ?
VBA Code:
Sub CheckOfCharacters()
    Dim i As Integer, str As String
str = ActiveCell.Value
'MsgBox ActiveCell.Font.Name
    For i = 1 To Len(str)
        Debug.Print Mid(str, i, 1) & "  =  " & Asc(Mid(str, i, 1))
        'Debug.Print Mid(str, i, 1) & "  =  " & AscW(Mid(str, i, 1))
    Next
End Sub
 
Upvote 0
Not sure, works great on mine. Make google your friend.

Google WAS my friend! Just had to make a slight change and it works perfect:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Not Intersect(Target, Range("E10")) Is Nothing Then
        With New DataObject
            .SetText Target.Text
            .PutInClipboard
        End With
    End If

End Sub

Thanks for your help!
 
Upvote 0
Solution
Great, for the rest of us, what was the change?

Changed this:

VBA Code:
If Not Intersect(Target, Sheet1.Range("D1:D50")) Is Nothing Then

To this:

VBA Code:
If Not Intersect(Target, Range("E10")) Is Nothing Then
 
Upvote 0
Thanks jmpatrick. The sheet name, while probably not required in the worksheet code, shouldn't have prevented from working. I generally write code very explicitly; maybe to a fault. Whatever the reason, I am glad you got it working.

Doug
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top