Thursday, February 08, 2007

Send string to clipboard

I was needing to add text to the clipboard from an activecell but within a Userform and I did not want to see the flashing lines around the cell after it was added to the clipboard and so I looked around and found the below code located here: http://www.xtremevbtalk.com/archive/index.php/t-229994.html

User defined type not defined:

Dim MyDataObject As DataObject 'user defined type not defined
Set MyDataObject = New DataObject
MyDataObject.SetText worksheetHeader & vbTab & rowHeader & vbTab & ActiveCell.Value & vbTab & "FY05" & vbTab & "MAY"
MyDataObject.PutInClipboard
So I tried this and it worked like a charm. Here is my final code:
Private Sub CommandButton2_Click()
Dim MyDataObject As DataObject 'user defined type not defined
Set MyDataObject = New DataObject
MyDataObject.SetText ActiveCell.Value
MyDataObject.PutInClipboard

Unload Me
End Sub
This was put in a userform.

Wednesday, January 24, 2007

Make a Cell Range Flash Different Colors

http://www.ozgrid.com/VBA/MiscVBA.htm

This Procedure will make the range C3:G13 loop through 5 different colors. The changes occur at 2 second intervals. Note the Dim iCount outside the Procedure, this makes it a Module level variable and thus it keeps its value between calls.
Dim iCount As Integer
Sub ColorChange()
Dim dTime As Date
''''''''''''''''''''''''''''''
'Will make range of cells, or single cell change colors _
at 2 second intervals

'Written by OzGrid.com
'''''''''''''''''''''''''''''''
dTime = Now
Application.OnTime dTime + TimeValue("00:00:02"), "ColorChange"
iCount = iCount + 1
Range("C3:G13").Interior.ColorIndex = Choose(iCount, 3, 36, 50, 7, 34)
If iCount = 5 Then
iCount = 0
Application.OnTime dTime + TimeValue("00:00:02"), "ColorChange", , False
End If