Excel Paste and VB.NET

G

Guest

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
 
N

NickHK

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top