Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Copy & Paste - Unsafe?

Hi, I'm hoping that an MVP can help settle a dispute (and save me some
reprogramming).

I have written a consolidation routine that takes data from a number
of formatted workbooks and consolidates it into a single 'Master_Data'
sheet.

As the code loops through each source workbook it defines the area to
be copied then copies and pastes it to the Master_Data sheet using the
following 2 lines of code...

rngAllocation.Copy

rngMaster.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False

During a code review, a colleague pointed out that this was unsafe
because another Excel application could be running at the same time on
the dual processor server and use the Windows paste buffer between my
code's copy and paste buffer operations, causing my code to paste the
wrong information.

I've never heard of this happening. Is there a slight risk?

Best regards, Nick H
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Copy & Paste - Unsafe?

Sorry, I cant answer that question because it is not something that I have
ever experienced.

You can reduce the possibility of such an occurrence by adding:

Application.CutCopyMode=False to Clear The Clipboard after pastespecial
instruction.

Better still, try and avoid using copy & thus by-pass using the clipboard
altogether using an approach like following:

ringmaster.value = rngAllocation.Value

--
jb


"Nick H" wrote:

Hi, I'm hoping that an MVP can help settle a dispute (and save me some
reprogramming).

I have written a consolidation routine that takes data from a number
of formatted workbooks and consolidates it into a single 'Master_Data'
sheet.

As the code loops through each source workbook it defines the area to
be copied then copies and pastes it to the Master_Data sheet using the
following 2 lines of code...

rngAllocation.Copy

rngMaster.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False

During a code review, a colleague pointed out that this was unsafe
because another Excel application could be running at the same time on
the dual processor server and use the Windows paste buffer between my
code's copy and paste buffer operations, causing my code to paste the
wrong information.

I've never heard of this happening. Is there a slight risk?

Best regards, Nick H

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Copy & Paste - Unsafe?

I'd still be interested in an answer to the original question, if
anyone else can offer some insight?

However...

---snip---
rngmaster.value = rngAllocation.Value

---snip---

....thanks jb that does the job - and I'm kicking myself for not
thinking of it, having gone to all the trouble of defining both ranges
and making them the same size. Doh! Too much pressure to think
straight I guess

btw, if anyone else decides this is the method for them please note
that if your source range has multiple areas (as mine does actually)
then the destination range must have the same number of areas and they
must be the same size as the source areas. You then need to loop
through each area and equate them separately. Like so...

For i = 1 To rngAllocation.Areas.Count
rngMaster.Areas(i).Value = rngAllocation.Areas(i).Value
Next i

....the same goes for copy & paste but I was trying to keep the
original question simple. ;^)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Copy & Paste - Unsafe?

Nick,
I pressed post before completing my earlier response - I was going to
mention that ranges should be same size but you have already covered. I alos
was going to suggest that you can use copy where needed like this:

rngAllocation.Copy Destination:=Sheet2.Range("A1")

which should also by-pass the clipboard.

Hope useful


--
jb


"Nick H" wrote:

I'd still be interested in an answer to the original question, if
anyone else can offer some insight?

However...

---snip---
rngmaster.value = rngAllocation.Value

---snip---

....thanks jb that does the job - and I'm kicking myself for not
thinking of it, having gone to all the trouble of defining both ranges
and making them the same size. Doh! Too much pressure to think
straight I guess

btw, if anyone else decides this is the method for them please note
that if your source range has multiple areas (as mine does actually)
then the destination range must have the same number of areas and they
must be the same size as the source areas. You then need to loop
through each area and equate them separately. Like so...

For i = 1 To rngAllocation.Areas.Count
rngMaster.Areas(i).Value = rngAllocation.Areas(i).Value
Next i

....the same goes for copy & paste but I was trying to keep the
original question simple. ;^)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Copy & Paste - Unsafe?

On 18 Aug, 17:20, john wrote:
Nick,
I pressed post before completing my earlier response - I was going to
mention that ranges should be same size but you have already covered. I alos
was going to suggest that you can use copy where needed like this:

rngAllocation.Copy Destination:=Sheet2.Range("A1")

which should also by-pass the clipboard.


Except that method won't work with PasteSpecial - Thanks for your help
though John.

Br, Nick H
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
potentially unsafe attachment KIRK Excel Discussion (Misc queries) 0 September 28th 07 08:00 PM
Cut is unsafe - call for solutions cjakeman Excel Programming 2 June 11th 07 08:15 AM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM
This application is about to initialize controls that might be unsafe. ... [email protected] Excel Programming 2 March 10th 05 04:21 AM
Unsafe ActiveX Controls Issue Matthew Wieder Excel Programming 0 July 29th 04 02:57 PM


All times are GMT +1. The time now is 03:11 AM.

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"