Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Pasting within an Addin

Hello!

I have the following code within an addin:

ThisWorkbook.Sheets("Sheet1").Range("A1").Copy
ThisWorkbook.Sheets("Sheet2").Range("B2").PasteSpe cial _
xlPasteValues, skipblanks:=true

Running this with at least one visible workbook open works
fine, but if no workbooks are open I get a run time
error 'Method PasteSpecial of object Range failed' on the
second line.

This alternative line work fine however:
ThisWorkbook.Sheets("Sheet1").Range("A1").Copy _
Destination:=ThisWorkbook.Sheets("Sheet2").Range(" B2")

Unfortunately I need to use the skipblanks and transpose
options, so need to use pastespecial. Any ideas?

Cheers,
Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Pasting within an Addin

Close all visible workbooks

go to the edit menu.

Note that copy and paste are not available. This is the source of your
problem
maybe have the code see if there are any visible workbooks and if not,
create one, then delete it after.

Otherwise, loop through your range and perform the update with the required
behavior by doing assignments.

--
Regards,
Tom Ogilvy


"Dave Ramage" wrote in message
...
Hello!

I have the following code within an addin:

ThisWorkbook.Sheets("Sheet1").Range("A1").Copy
ThisWorkbook.Sheets("Sheet2").Range("B2").PasteSpe cial _
xlPasteValues, skipblanks:=true

Running this with at least one visible workbook open works
fine, but if no workbooks are open I get a run time
error 'Method PasteSpecial of object Range failed' on the
second line.

This alternative line work fine however:
ThisWorkbook.Sheets("Sheet1").Range("A1").Copy _
Destination:=ThisWorkbook.Sheets("Sheet2").Range(" B2")

Unfortunately I need to use the skipblanks and transpose
options, so need to use pastespecial. Any ideas?

Cheers,
Dave



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Pasting within an Addin


Try this:

application.screenupdating = false
Application.isaddin = false

ThisWorkbook.Sheets("Sheet1").Range("A1").Copy
ThisWorkbook.Sheets("Sheet2").Range("B2").PasteSpe cial _
xlPasteValues, skipblanks:=true

application.isaddin = true
application.screenupdating = true

Hope this work

--
Abh
-----------------------------------------------------------------------
Abhi's Profile: http://www.excelforum.com/member.php...fo&userid=1585
View this thread: http://www.excelforum.com/showthread.php?threadid=27328

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting on Filtered Data Sheets without pasting onto hidden cells CCSMCA Excel Discussion (Misc queries) 1 August 28th 05 01:22 PM
Pasting numbers and formulas without pasting format. Dan Excel Discussion (Misc queries) 3 March 27th 05 03:47 AM
Remove Excel AddIn from AddIn List !! Help carl Excel Programming 2 December 8th 03 03:36 PM
AddIn Robin Clay[_2_] Excel Programming 2 September 15th 03 07:08 PM
AddIn Robin Clay[_2_] Excel Programming 6 September 8th 03 11:08 AM


All times are GMT +1. The time now is 06:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"