Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ClearContents or ClearFormats also clears Clipboard. How can I keep the clipboard?

Hi,

I have following code in my workbook:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Call Excel.ActiveSheet.UsedRange.ClearContents
Call Excel.ActiveSheet.UsedRange.ClearFormats
Excel.ActiveSheet.Cells(1, 1).Value = "test"
End Sub

When I copy a value from Sheet1 and try to Paste it on Sheet2 the paste
doesn't work. For some reason both ClearContents and ClearFormats clear
the clipboard as well.

Does anybody know a workaround for this so that the clipboard is still
available?

Thx,
Reto

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ClearContents or ClearFormats also clears Clipboard. How can I keep the clipboard?


Write clearing-contents/format code before copying and try...


--
ilyaskazi
------------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...o&userid=23969
View this thread: http://www.excelforum.com/showthread...hreadid=493644

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ClearContents or ClearFormats also clears Clipboard. How can I keep the clipboard?

Unfortunately I cannot do this. On a tab change I want to clear the
entire sheet (content and formatting) and intialize cells using VBA. So
no change in sequence possible. At the moment the only way I see is
that I manually must clean the sheet. This way it won't clear the
clipboard.

ws.UsedRange.Value = ""
ws.UsedRange.Interior.ColorIndex = xlNone
.......

Regards,
Reto
www.collaboral.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ClearContents or ClearFormats also clears Clipboard. How can I keep the clipboard?

Since I'm dependent on calling ClearContents and ClearFormats I found a
pretty nice solution. All what I do is I remember the clipboard
manually. I store it when a sheet gets deactivated and read it back
after the new worksheet was activated. On save I clear the clipboard.

Works perfect!

Cheers,
Reto
www.collaboral.com

Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As
Long) As Long

Public Sub GetClipboard()
On Error Resume Next

m_clipboard.GetFromClipboard
m_clip = m_clipboard.GetText
End Sub

Public Sub SetClipboard()
On Error Resume Next

m_clipboard.SetText m_clip
m_clipboard.PutInClipboard
End Sub

Public Sub ClearClipboard()
On Error Resume Next

OpenClipboard 0&
EmptyClipboard
CloseClipboard
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
' Clear the clipboard to maintain the standard behavior of the
Excel clipboard which gets cleared after a save
ClearClipboard
End Sub

Private Sub Workbook_SheetActivate(ByVal Target As Object)
Call Excel.ActiveSheet.UsedRange.ClearContents
Call Excel.ActiveSheet.UsedRange.ClearFormats

SetClipboard
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Target As Object)
GetClipboard
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ClearContents or ClearFormats also clears Clipboard. How can I keep the clipboard?

a little bug fix...


Public Sub SetClipboard()
On Error Resume Next

If m_clip < "" Then
m_clipboard.SetText m_clip
m_clipboard.PutInClipboard
End If
End Sub

Public Sub ClearClipboard()
On Error Resume Next

m_clip = ""
OpenClipboard 0&
EmptyClipboard
CloseClipboard
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ClearContents or ClearFormats also clears Clipboard. How can I keep the clipboard?

a little bug fix...


Public Sub SetClipboard()
On Error Resume Next

If m_clip < "" Then
m_clipboard.SetText m_clip
m_clipboard.PutInClipboard
End If
End Sub

Public Sub ClearClipboard()
On Error Resume Next

m_clip = ""
OpenClipboard 0&
EmptyClipboard
CloseClipboard
End Sub

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
launching Excel clears clipboard Richard Excel Discussion (Misc queries) 0 July 17th 08 01:51 PM
Strange behaviour - loading Excel clears Clipboard Trevor Shuttleworth Excel Discussion (Misc queries) 1 August 19th 06 10:04 PM
Worksheet_Activate event clears clipboard? Andibevan[_2_] Excel Programming 5 June 7th 05 03:09 PM
Worksheet_SelectionChange clears clipboard - can I stop this? ned Excel Programming 0 June 9th 04 07:02 PM
Really Need Help: side effect clears clipboard!!! Bura Tino Excel Programming 3 February 28th 04 12:44 PM


All times are GMT +1. The time now is 12:19 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"