1

I am trying to copy a text from a range, but if someone press "ESC" or anything else, this information is lost.

I copy with this macro:

Sub Copiar_Reposta()

With Application
    .ScreenUpdating = False
End With

Planilha1.Select
Range("A45").Select
Application.CutCopyMode = False
Application.Wait (Now() + TimeValue("00:00:01"))
Application.SendKeys "{F2}", True
Application.SendKeys "+{HOME}", True
Application.SendKeys "^C", True
Application.SendKeys "{ESC}", True

Planilha3.Select

With Application
    .ScreenUpdating = True
End With

End Sub

Immediately the "NUM LOCK" turns off, and after trying to fix it, this macro stopped working as well.

Is there a way to copy the information from a cell without losing it after? Or, is there a way to fix my macro that stopped working suddenly.

Copy like this: Copying with "F2" and "CTRL + C"

Community
  • 1
  • 1
Guilherme Matheus
  • 573
  • 10
  • 30
  • What do you want to do with the copied text? `SendKeys` can be unreliable. More context would be helpful to properly answer your question. – BigBen Aug 14 '18 at 17:01
  • 1
    you dont need to use `SendKeys` to copy a value... you can just write `Planilha3.Range("A45").Value = Planilha1.Range("A45").Value` instead of all of that code (assuming that's your destination cell) – Marcucciboy2 Aug 14 '18 at 17:01
  • My destination it's not in Excel, that's why I need copy from "inside" that cell. – Guilherme Matheus Aug 14 '18 at 17:03
  • 1
    In that case, you can use this function to directly copy something to the clipboard https://stackoverflow.com/a/25336423/2727437 – Marcucciboy2 Aug 14 '18 at 17:09
  • What should I do ? **Range("A45").Select CopyText Selection.Text** after insert CopyText macro ? @Marcucciboy2 – Guilherme Matheus Aug 14 '18 at 17:31
  • `CopyText Planilha1.Range("A45").Text` – Marcucciboy2 Aug 14 '18 at 17:32
  • I did it what you said, and after paste it gets two blocks, not the text. Like this: � I dont know how to insert Picture here to show you. – Guilherme Matheus Aug 14 '18 at 17:40
  • Hmm. Maybe give this a try? https://stackoverflow.com/a/35486033/2727437 – Marcucciboy2 Aug 14 '18 at 18:20
  • 1
    I searched as well, that problem is a bug that occurs when "File Explorer" is open, I closed and it worked, but I'd like to have another code for backup. Everyone say that we could use copy to API Windows, so in your link, where do I set the text ? @Marcucciboy2 – Guilherme Matheus Aug 14 '18 at 18:24
  • To include this you actually would keep the code that you already have and include this code in a new module. https://www.ablebits.com/office-addins-blog/2013/12/06/add-run-vba-macro-excel/ – Marcucciboy2 Aug 14 '18 at 18:25
  • 1
    Great, it worked !! **You're the best, thank you!!** – Guilherme Matheus Aug 14 '18 at 18:29
  • That's great news, I'm glad I could help and that you beat me to some of the research haha :) – Marcucciboy2 Aug 14 '18 at 18:36

1 Answers1

0

Just to mark the question as answered, I solved the problem with the help from @Marcucciboy2, using this link Text To Clipboard in VBA Windows 10 Issue and this link Excel VBA code to copy a specific string to clipboard to copy information to my clipboard, when I searched the problem is a bug that occurs when "File Explorer" is open, I closed and it worked. But I'm not using this function anymore.

Guilherme Matheus
  • 573
  • 10
  • 30