Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
| Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 29th, 2006, 09:15 AM
Registered User
 
Join Date: Aug 2006
Location: Weymouth, Dorset, United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel VBA Problems with copy and paste

I've written quite a lot of VBA code for a spreadsheet which works fine, but I now find that I can't copy and paste!

I copy a cell in the normal way, but when I click onto the target cell, the paste button grays out.

This doesn't happen on the other worksheets in the workbook (but there are no VBA calls on these sheets)

Is it possible to inadvertently disable copy and paste?

I'd appreciate any help in this

Thanks!



  #2 (permalink)  
Old August 29th, 2006, 02:28 PM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes.. there are a few ways... how are you trying to paste.. by right click? or via the menu bar? try going into the imediate window and type
Code:
Application.CommandBars("Cell").Reset
this should enable rightclick pasting, but wil lalso reset any right click menues you have made.. hope this helps

  #3 (permalink)  
Old August 30th, 2006, 10:18 AM
Registered User
 
Join Date: Aug 2006
Location: Weymouth, Dorset, United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a list of types of expenditure arranged in a row with each row corresponding to a particular expense or outgoing.
Columns M,N,O are active - i.e right clicking them enables the user to assign a value in the earlier columns to a different type of expenditure

Right clicking an active cell displays only my customised options. Right clicking an non active cell displays the standard Excel options including copy and paste

I want to able to copy and paste data and formulae between the non active cells. If I either right click and copy or press the copy button, it seems that data is copied to the clipboard. The paste button becomes active, and there is the standard dashed flashing border around the cell. But when I click on the target cell, the paste button becomes inactive, the flashing border disappears and right clicking only shows a grayed-out Paste option.

I've tried to put the code you suggested in the immediate window but with no effect.

I'd be grateful for any other suggestions



  #4 (permalink)  
Old August 30th, 2006, 11:02 AM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there any code in the Worksheet_selectionChange macro? ie Application.CutCopyMode = False

  #5 (permalink)  
Old August 30th, 2006, 03:38 PM
Registered User
 
Join Date: Aug 2006
Location: Weymouth, Dorset, United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello JRogers

Thanks for persisting with me
Yes there is the following code
If the Row > 9 and the column is between 10 and 15 then the cells are active
(i.e. they have a customised right-click function)
Otherwise they are normal
btnEdit and btnClearcodes are two custom buttons that have nothing to do with Copy and Paste

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Row, Col As Integer
Dim Log As Boolean
Dim Payt As Single
Dim CellPay As Variant
Dim CellVat As Variant
Row = Target.Row
Col = Target.Column
Log = Col >= 10 And Col <= 15
If Row < 9 Or Not Log Then
btnEdit.Enabled = False
Exit Sub
Else
btnClearcodes.Enabled = True
btnEdit.Enabled = True
End If
End Sub

John


  #6 (permalink)  
Old August 31st, 2006, 03:13 AM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you loose the link to the clipboard when you execute these lines
btnEdit.Enabled = False
btnClearcodes.Enabled = True
btnEdit.Enabled = True

is it absolutely necesasry to include these lines.. can you not put some validation checks in the button_click such that if you are not in the correct range then do nothing, otherwise carryon as normal

  #7 (permalink)  
Old September 1st, 2006, 05:14 AM
Registered User
 
Join Date: Aug 2006
Location: Weymouth, Dorset, United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello jrogers

That solves the problem! Having removed the lines you mentioned, the cut and paste function now works.

I would not have guessed that in a million years.

But why does this happen? Why does enabling or disabling a button lose the link to the clipboard?

No matter, I'll have to think about a different way to achieve the result I want

Thanks very much for this advice. I'm most grateful

John



Similar Threads
Thread Thread Starter Forum Replies Last Post
XMLSpy: copy data from excel, paste in XMLSpy 2004 xmler XML 1 November 26th, 2008 03:33 AM
Excel VBA copy & paste wensmail Excel VBA 1 September 17th, 2007 11:13 PM
Copy contents of Word doc & Paste in Excel - How?? robear Javascript How-To 1 August 23rd, 2006 03:22 PM
How to Copy contents of Word doc & Paste in Excel robear Pro PHP 0 August 21st, 2006 12:25 PM
Copy data from webpage to excel using vba kg8299 Excel VBA 0 April 5th, 2006 03:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.