![]() Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat As LongPtr, _ ![]() Private Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _ ![]() Private Declare PtrSafe Function Empt圜lipboard Lib "user32" () As LongPtr Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As LongPtr Private Declare PtrSafe Function CloseClipboard Lib "user32" () As LongPtr Private Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As LongPtr, _ Private Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr Private Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr To accomplish this, I will copy the selected cells to clipboard, save the clipboard to a text variable, and then copy this text back to clipboard.Ĭopy the following into a new module and then run the last sub: 'Handle 64-bit and 32-bit Office It should be possible to pass the data from the VBA array to the application, but hard to say without knowing more about the application. Personally, I would avoid SendKeys and use arrays. This one is my favorite reference on how you pass ranges to vba arrays and back: Now that I think better, I think this is an overkill. When run from VBA, SendKeys opens the object browser, which is what F2 does when pressed at the VBA view :) Also, for a full range, you will have to loop over the cells, copy them one by one and paste them one by one to the application. For example, the code above works only when the macro is executed from excel, not from VBA. There is a trick that works for a single cell and for numbers and text only (no formulas): Sub test()īut most developers avoid SendKeys because it can be unstable and unpredictable. Sheet1.Cells(1, 2).PasteSpecial xlPasteValuesĬopy copies the entire part, but we can control what is pasted.ĪFAIK, there is no straighforward way to copy only the text of a range without assigning it to a VBA object (variable, array, etc.). Something like this? Sheet1.Cells(1, 1).Copy
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |