Excel Help In VB.NET

MadMaxx

Active member
Joined
Nov 16, 2003
Messages
37
Hey all,

Im new to the whole office integration side of VS.NET. I have to open an excel file, dump data into it and then print it.

The problem is that I cant for the life of me figure out how to insert a column. When I try I keep getting the same error.

Here is where it errors out.

Code:
oSheet.Columns.Insert(Excel.XlInsertShiftDirection.xlShiftToRight,False)

The error message says that it cant shift non blank cells off the worksheet.

I know how to put data in but this is the only part that is holding me up.

Thanks to anyone who replys.
 
Where are you actually wanting to add the column?

I think you need to specify it i.e.:


oSheet.Columns(2).Insert(Excel.XlInsertShiftDirection.xlShiftToRight,False)

To insert a column in at col B etc.

You could also use:

oSheet.Range("b2").EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight,False)

etc.

HTH

:)
 
Back
Top