Merging Cells in Excel 2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm a beginner to moderate programmer who's fiddling around with automating
Excel, in particular after being able to have the user fill out a form and it
then generate the workbook. I can't quite figure out how to get it to Merge
cells together - I've found how to do it (I think) but can't nut out the
syntax. Any help with this would be much appreciated (I've tried looking for
online tutorials, but the ones I've found never touch merging).

Cheers,
Damian A.
 
A trick I learned that works with most Microsoft products is to go to
Tools->Macros->Record->Record New Macro and then do whatever you are trying
to figure out what to do. When you view the macro, you then have the sytax. I
don't have .Net at home (so it's in VB, sorry), but try something like this:

Range("A1:B1").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With

I hope this helps.
Susan
 
Hi Damian A.

Try this out.

Excel.Application xl = new Excel.ApplicationClass();

Excel.Workbook wb = xl.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);

Excel.Worksheet ws = (Excel.Worksheet)wb.ActiveSheet;

ws.Cells[1,1] = "Testing";

Excel.Range range = ws.get_Range(ws.Cells[1,1],ws.Cells[1,2]);

range.Merge(true);

range.Interior.ColorIndex =36;

xl.Visible =true;

Cheers,

Kids
 
Just tried it out - Works a wonder. I was close, but I guess thats the
trouble with teaching yourself - Tis a wee bit harder than normal. Thanks!
 
Back
Top