VBA .PutInClipboard error

westc4

Board Regular
Joined
Aug 1, 2012
Messages
89
Office Version
  1. 365
Platform
  1. Windows
I am using Excel 2010 and have an error with a macro that I have used for the last two years with out a problem. Now when I attempt to run the macro it errors out at .objData.PutInClipboard The issue only happens every other time I run it?

I have two text boxes that get the information that needs to be copied and then pasted both in excel and then again as the file name. Here is what I have...

Code:
    Dim actName As String
    Dim actNumber As String
    Dim objData As DataObject
    Dim strClipBoard As String
    Set objData = New DataObject

    actName = InputBox("Please enter the Account Name", "Account Name")
    actNumber = InputBox("Please enter Payer Number", "Payer Number")
    Range("A1").Value = actName & " - " & actNumber

    objData.SetText ""
    objData.PutInClipboard
    strClipBoard = actName & "-" & actNumber
    objData.SetText strClipBoard
    objData.PutInClipboard    

    
    Application.Dialogs(xlDialogSaveAs).Show

When I debug the problem appears to be at the objData.PutInClipboard

Since I use this macro over 100 times it is really annoying that this has starting happening... I have tried to clear the clipboard, but that does not seem to work with the issue...

help please
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
What's the error?

Also, what are you using the clipboard for?
 
Upvote 0
What's the error?

Also, what are you using the clipboard for?



Run-Time error '-2147221040 (800401d0)':

DataObject:PutInClipboard OpenClipbard Failed


I use the clipboard to name the file when it is saved-as and then again as the subject line when the files is emailed.

Thank you,
 
Upvote 0
Do you mean you are pasting the filename into the save as dialog?

If you do there's no need to do that, you could use something like this instead.
Code:
  Application.Dialogs(xlDialogSaveAs).Show strClipBoard
 
Upvote 0
Yes, thank you I will add that addition to the code, but I am still getting the error every other time I run the macro.

Any ideas on how to correct this?
 
Last edited:
Upvote 0
If you use what I suggested you wouldn't need to use the clipboard.
 
Upvote 0
I can do that. I still use the copied data as an email subject line, but I can work around that.

Thank you
 
Upvote 0
Can you post the code for the email?
 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,275
Members
449,093
Latest member
Vincent Khandagale

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