Results 1 to 5 of 5

Thread: VB.NET and EXCEL Paste Special Formatting only

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    34

    VB.NET and EXCEL Paste Special Formatting only

    I am trying to copy some formatting from one range of cells and paste the formatting only to another range of cells and am having trouble. The last line is where I am having trouble.

    TIA
    Bill

    Dim xl As Object
    Dim orng As Object
    Dim wrkbk As Object
    Dim wrksht As Object

    xl = CreateObject("Excel.Application")
    xl.Visible = False
    xl.DisplayAlerts = False
    wrkbk = xl.Workbooks.Add
    wrksht = wrkbk.ActiveSheet


    wrksht.Range("A4").ReSize(2, 17).Copy 'copy formatting from A4:Q5
    wrksht.Range("A6").ReSize(200, 17).PasteSpecial 'paste formats to A6:Q205

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: VB.NET and EXCEL Paste Special Formatting only

    The easiest way to work out syntax for excel, is to record a macro of yourself manually performing the same actions, then read the autogenerated VBA code...

  3. #3
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: VB.NET and EXCEL Paste Special Formatting only

    When doing it in Excel (VBA), the last line would look like this:

    Code:
    wrksht.Range("a6").Resize(200, 17).PasteSpecial xlPasteFormats

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    34

    Re: VB.NET and EXCEL Paste Special Formatting only

    When doing it in Excel (VBA), the last line would look like this:

    wrksht.Range("a6").Resize(200, 17).PasteSpecial xlPasteFormats

    Right, but I am doing this inside vb.net and I need the syntax for doing it there.

  5. #5
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: VB.NET and EXCEL Paste Special Formatting only

    Code:
    Imports Microsoft.Office.Interop.Excel
    ...

    Code:
    wrksht.Range("A6").ReSize(200, 17).PasteSpecial(XlPasteType.xlPasteFormats)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width