View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
NickHK[_3_] NickHK[_3_] is offline
external usenet poster
 
Posts: 415
Default Excel Paste and VB.NET

Eric.
Just use the Excel Object Model to perform the action.

objSheet.Range("C7").Copy
objSheet.Range("E7").PasteSpecial Paste:=xlFormats
(Or the .Net translation)

NickHK

"Eric Weller" ...
All:
I have a VB.NET application that reads an Excel Template Spreadsheet to
get
a specific cell's formatting (border, font, size, etc). I want to copy
the
cell's formatting to another cell. I am using VB.NET and here is the code
I
am using:

range = objSheet.Range("A1", "A1") ' range defined as Excel.range
System.Windows.Forms.Clipboard.SetDataObject(range .Cells) ' copy to
clipboard
objSheet.Range("A20", "A20").Cells.Select() ' objSheet defined as
Excel.Sheet
objSheet.PasteSpecial()

When the PasteSpecial method executes, I get the following error:

Err.Number=1004
Err.Desc=Exception from HRESULT: 0x800A03EC.
Err.Source=Interop.Excel

How can I programitically copy one cell's formatting to another cell?

Thanks in advance!
Eric Weller