Author Topic: Copy Excel Range to the Clipboard  (Read 2629 times)

0 Members and 1 Guest are viewing this topic.

Bill Tillman

  • Guest
Copy Excel Range to the Clipboard
« on: October 29, 2012, 10:37:42 AM »
I need to get the contents of a range in an Excel spreadsheet into the clipboard but can't seem to get it right.

Code: [Select]
vExcelRange1 = vExcelSheet2.Range("B1:K93")
vExcelRangel.Copy()

This works but only if I keep the Excel app open. I need a method of keeping the clipboard contents static until I can copy it into AutoCAD, which is after I close down Excel.

I've tried this as well, but for some reason the clipboard data is not available to me once Excel closes down

Code: [Select]
vExcelRange1 = vExcelSheet2.Range("B1:K93")
Clipboard.SetDataObject(vExcelRange1, True)
« Last Edit: October 29, 2012, 10:58:39 AM by Bill Tillman »

Drafter X

  • Swamp Rat
  • Posts: 578
Re: Copy Excel Range to the Clipboard
« Reply #1 on: October 29, 2012, 10:56:11 AM »
not positive this will work, I may have the states reversed but before you exit excel add this maybe

Application.CutCopyMode = False
Application.DisplayAlerts = False



if it doesn't work try changing the first one to true.. been a while and I am away from excel.
CadJockey Militia Commander

Bill Tillman

  • Guest
Re: Copy Excel Range to the Clipboard
« Reply #2 on: October 29, 2012, 11:05:58 AM »
Thanks but that did not work in either form. True or False. Still hacking at this.

Drafter X

  • Swamp Rat
  • Posts: 578
Re: Copy Excel Range to the Clipboard
« Reply #3 on: October 29, 2012, 11:41:12 AM »
hmmmmm....  im grasping at straws here but...

how about..

Application.EnableEvents=False
 your code here



and last line of code...
Application.EnableEvents=True

CadJockey Militia Commander

Bill Tillman

  • Guest
Re: Copy Excel Range to the Clipboard
« Reply #4 on: October 29, 2012, 12:40:21 PM »
I am using DisplayAlerts=False and when I set it to true, the alert does popup allowing me to save the clipboard contents for later use. Still it's a difficult call to understand why in VBA code this same process is so simple and works like a champ. But from VB.NET this is all but impossible. I found that by launching AutoCAD I could copy the clipboard into the model space but the formatting, borders, colors, etc... are all missing. No gridlines or nothing like when we were running this from a macro with Excel.

Oh yes, I tried the suggestion in your second post and it was not the answer. Thanks anyway.

Drafter X

  • Swamp Rat
  • Posts: 578
Re: Copy Excel Range to the Clipboard
« Reply #5 on: October 29, 2012, 12:47:03 PM »
dunno, did see this article, maybe it is related?
http://www.fmsinc.com/MicrosoftAccess/Errors/ExcelPaste/Clipboard.html
CadJockey Militia Commander