Clipboard and null

Snypa

New Member
Joined
Nov 1, 2013
Messages
45
Hello,
I have the following code:


Code:
    tmpClipBoard = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
    
    ...
 
        If tmpClipBoard <> Null Then
            MsgBox (tmpClipBoard)
                With New MSForms.DataObject
                    .SetText tmpClipBoard
                    .PutInClipboard
                End With
        ElseIf tmpClipBoard = Null Then
                MsgBox ("Null")
        End If

the msgboxs are just my debugging, can be ignored.

tmpClipBoard might be null, as I get a 'invalid use of null' error. This code stops the error but neither branch is executed. What am I doing wrong?
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Is there an issue with:

Code:
If tmpClipBoard <> Null Then

Because if the variable is not null this branch should execute, no?
 
Upvote 0
Instead of your method try

Code:
On Error Resume Next
tmpClipBoard = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
With New MSForms.DataObject
   .SetText tmpClipBoard
   .PutInClipboard
End With

On the line below where the error occurs use this method to handle it if necessary
Code:
If Err.Number > 0 Then
   Exit Sub
Else
   your code
End If
 
Last edited:
Upvote 0
Hello,
I have the following code:


Code:
    tmpClipBoard = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
    
    ...
 
        If [B][COLOR="#FF0000"]Not IsNull(tmpClipBoard)[/COLOR][/B] Then
            MsgBox (tmpClipBoard)
                With New MSForms.DataObject
                    .SetText tmpClipBoard
                    .PutInClipboard
                End With
        ElseIf [B][COLOR="#FF0000"]IsNull(tmpClipBoard)[/COLOR][/B] Then
                MsgBox ("Null")
        End If
tmpClipBoard might be null, as I get a 'invalid use of null' error. This code stops the error but neither branch is executed. What am I doing wrong?
VB has an IsNull function that you should use instead of testing against the Null keyword. This untested, but try making the changes I show in red above and see if that works for you. On a side note, you can change your ElseIf statement to a simple Else statement since if the first If test fails, the only other possibility is the object is in fact Null, so there is no need to specifically test for it.
 
Upvote 0
Thank you guys, very much. I will use IisNull() in future [MENTION]Rick Rothstein[/MENTION]
 
Last edited:
Upvote 0
It seems to me that the latest update on 365 has drastically changed the clipboard.
If I copy something it no longer shows on the clipboard shown from the "Home" on the ribbon, so presumably it is not using the Office clipboard; but it also does not clear with the "Application.CutCopyMode = False" which clears the Windows clipboard, so presumably it is not using that either.
Rick's code shown above does work with it; except that I cannot test the "null" solution as I seem to be unable to clear the "new" clipboard.
I need to be able to clear this, and then be able to test to see if something has been copied onto it.

Can anyone help, please?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top