Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8548313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:28:00+00:00 2026-06-11T13:28:00+00:00

I want to mock the Format painter behaviour while cycling throug last 8 formatting.

  • 0

I want to mock the Format painter behaviour while cycling throug last 8 formatting.
For that purpose I store last 8 captured Range in List<> object in cycle format.
While applying, I take out each range call COPY method to copy that range on clipboard and then call PasteSpecial method on destination range like below

RangeInfo tempRangeInfo = listRangeInfo[Counter]; 
//Copy to clipboard
                        tempRangeInfo.CopiedRange.Copy();
                        selection.PasteSpecial(xl.XlPasteType.xlPasteFormats,  xl.XlPasteSpecialOperation.xlPasteSpecialOperationNone,
                            false, false);

But if I delete the original range I get:

PasteSpecial method of Range class failed” error.

Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:28:01+00:00Added an answer on June 11, 2026 at 1:28 pm

    When you copy in Excel (the copied region has the marching ants border) the data isn’t actually on the clipboard. Excel uses the clipboard to transfer from the source cells in real-time when you paste. It does this so that it can rework formulas to new relative cell references during the paste operation. If you delete the source cells, then Excel has nothing from which to pull data during the paste operation.

    VBA does not have native support to work directly with the clipboard. However, you can add MSForms to the VBA project and then declare an object that does support Clipboard functions.

    See the follow web site for instructions and examples how to access the Clipboard directly from VBA:

    http://www.cpearson.com/excel/Clipboard.aspx

    For me, I did not have MSForms in the list of available references, as suggested on cpearson‘s site, but I did search the C:\ drive for FM20.dll and found it buried in some obscure folder. I copied it to the root of C:\ and was able to add it as a reference by click browse from the add references dialog.

    Once MSForms is available, you can use this code to copy text to the clipboard that persists after the source cells are removed.

    Public Sub Test()
      Dim obj As New MSForms.DataObject
      obj.SetText ActiveCell.Value
      obj.PutInClipboard
    End Sub
    

    This one copies formulas that persist:

    Public Sub Test()
      Dim obj As New MSForms.DataObject
      obj.SetText ActiveCell.Formula
      obj.PutInClipboard
    End Sub
    

    I don’t have time to figure out how to copy the cell’s format to the clipboard, but it seems that this is the direction that you need to go, if you want to persist the copied values so you can paste them after the source cells are removed.

    Edit #1

    Even though the Windows Clipboard can store multiple formats for one item (e.g., RTF and Text versions of a copied selection), it can only store one item at a time.

    The Office Clipboard doesn’t use the Windows Clipboard. It stores copied values itself, and can store many different selections. However, as of Office 2000, it could not be controlled via VBA (see How to use the Office 2000 Clipboard), and selections copied from Excel are either ‘paste text’ or ‘paste all’. There is no paste special to just paste the formats. I couldn’t find anything that says different for later versions of Office.

    Conclusion: The only way to use VBA to do a paste special is to have an active / valid / copied selection. So I agree that the only solution is to declare your own persistent global variables (e.g., a list of objects) and store the formats for each copied selection in the list. Since the clipboard really isn’t a viable solution, SetData and SetDataObject are irrelevant… If it proves impossible to capture the formatting of a cell in a single line of VBA code, you could always enumerate the formats of interest and set flags in your stored objects for later use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to mock a ServiceContract. The problem is that Moq (and Castle Dynamic-Proxy)
I have a URL in string format that I want to parse to get
I want to mock a method in the same class that I am testing.
If I want to mock a class that returns a string that is used
I have a method that i want to mock that takes an array as
I want to be able to mock the object that is returned by SPServer.Local
I'm using Mockito 1.9.0. I want mock the behaviour for a single method of
I want to mock the Microsoft.Office.Interop.Excel.Range (and the other Microsoft.Office.Interop.Excel interfaces) to unit test
I have concrete class that I want to mock. There are several annotated methods
Suppose I have a strongly typed caching interface that I want to mock. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.