Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Prevent Copy/Paste Q

I have the very simple code below that stops printing of a Document,
is it possible to have just as simple a code that will prevent Copy/
Paste from the Tool bar?

I've tried - ActiveSheet.EnableSelection = xlNoSelection. This works
when a user opens in XL but not Excel 2000

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Prevent Copy/Paste Q

What about putting this code in your worksheet code window. It just changes
the selection to A1 regardless of what they select:-

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
Sh.Range("A1").Select
End Sub

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Seanie" wrote:

I have the very simple code below that stops printing of a Document,
is it possible to have just as simple a code that will prevent Copy/
Paste from the Tool bar?

I've tried - ActiveSheet.EnableSelection = xlNoSelection. This works
when a user opens in XL but not Excel 2000

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Prevent Copy/Paste Q

Alan, that's very clever, I think it will work for me

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Prevent Copy/Paste Q

I have tried to create a macro that would insert the above in to This
Workbook by it is not appearing. Code I have tried is as below, any
idea what I've done wrong? I have other pieces of code that I have
used to populate TW and modified accordingly, but it is not appearing
and no errors are showing



Sub Populate_TW_3()

Dim StartLine As Long
Dim msg1 As String

Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If

msg1 = "Sh.Range(""A1"").Select"

With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("SheetSelectionChanges", "Workbook") + 1
..InsertLines StartLine, msg1
End With
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Prevent Copy/Paste Q

How are you calling Populate_TW_3(). Does it need to be marked as public?

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Seanie" wrote:

I have tried to create a macro that would insert the above in to This
Workbook by it is not appearing. Code I have tried is as below, any
idea what I've done wrong? I have other pieces of code that I have
used to populate TW and modified accordingly, but it is not appearing
and no errors are showing



Sub Populate_TW_3()

Dim StartLine As Long
Dim msg1 As String

Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If

msg1 = "Sh.Range(""A1"").Select"

With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("SheetSelectionChanges", "Workbook") + 1
..InsertLines StartLine, msg1
End With
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Prevent Copy/Paste Q

Try removing your error handling and see what happens. I assume that your
addin / whatever has a reference to be able to FindWindow and
lockWindowUpdate?

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Seanie" wrote:

I have tried to create a macro that would insert the above in to This
Workbook by it is not appearing. Code I have tried is as below, any
idea what I've done wrong? I have other pieces of code that I have
used to populate TW and modified accordingly, but it is not appearing
and no errors are showing



Sub Populate_TW_3()

Dim StartLine As Long
Dim msg1 As String

Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If

msg1 = "Sh.Range(""A1"").Select"

With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("SheetSelectionChanges", "Workbook") + 1
..InsertLines StartLine, msg1
End With
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Prevent Copy/Paste Q

Alan, on removing Err handler it points to this line, explaining Event
Handler is Invalid

StartLine = .CreateEventProc("SheetSelectionChanges", "Workbook") + 1

I haven't placed the text.. (ByVal Sh As Object, ByVal Target As
Range) but when I do (as per below) I get the same error message

StartLine = .CreateEventProc("SheetSelectionChanges(ByVal Sh As
Object, ByVal Target As Range)", "Workbook") + 1

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
Can you prevent Copy-Paste from changing formatting without macros DCramlet Excel Discussion (Misc queries) 6 May 30th 14 07:18 AM
Unable to prevent copy/paste of protected worksheet into new docum Richard R. Excel Programming 11 May 2nd 07 04:27 AM
Prevent changing size when copy&paste into another Excel Worksheet Michelle Excel Worksheet Functions 0 June 26th 06 04:30 PM
How to prevent copy/paste of cell with validation? Joe HM Excel Programming 0 May 11th 06 10:14 PM
prevent the copy and paste function sir Lancelot Excel Discussion (Misc queries) 1 December 8th 05 01:16 AM


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

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

About Us

"It's about Microsoft Excel"