Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert an excel column? 1

Status
Not open for further replies.

Webrookie

Programmer
May 18, 2000
112
US
All I want to do currently is add a column to an existing Excel Document from VFP 6.0 sp3.&nbsp;&nbsp;I can open it and change cell values all I want, but I need to add a column, so I recorded an Excel 2k macro, and modified code accordingly.<br><br>I get an error saying can't access insert property of range class.<br><br>please help!<br><br>*************************BEGIN CODE HERE*******************<br><br><br>oleExcel = Createobject (&quot;Excel.Application&quot;)<br>oleExcel.application.workbooks.open &quot;filename&quot;)<br><br>newcolumn = chr(13)<br><br>titlemo = 10<br>titleot = 11<br><br>shift1 = &quot;shift:=xltoright&quot;<br><br>with oleExcel<br><br> .columns(newcolumn + &quot;:&quot; + newcolumn).select<br> .range(str(newcolumn + &quot;6&quot;).activate<br> .Selection.Insert (shift1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;-- ERROR HERE!<br> .Selection.Insert (shift1)<br> .Selection.ColumnWidth = 1.57<br> .Range(newcolumn + titlmo).select<br> .ActiveCell.FormulaR1C1 = sfna<br> .Range(newcolumn + str(titlot)).select<br> .ActiveCell.FormulaR1C1 = &quot;Churn&quot;<br> .Range(newcolumn + str(titleot)).Select<br>&nbsp;&nbsp;&nbsp;&nbsp;.Selection.Borders(xlDiagonalDown).LineStyle = xlNone<br>&nbsp;&nbsp;&nbsp;&nbsp;.Selection.Borders(xlDiagonalUp).LineStyle = xlNone<br>&nbsp;&nbsp;&nbsp;&nbsp;.Selection.Borders(xlEdgeLeft).LineStyle = xlNone<br>&nbsp;&nbsp;&nbsp;&nbsp;.Selection.Borders(xlEdgeTop).LineStyle = xlNone<br>&nbsp;&nbsp;&nbsp;&nbsp;With .Selection.Borders(xlEdgeBottom)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.LineStyle = xlContinuous<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Weight = xlThin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ColorIndex = xlAutomatic<br>&nbsp;&nbsp;&nbsp;&nbsp;EndWith<br> .Selection.Borders(xlEdgeRight).LineStyle = xlNone<br>endwith<br>
 
Hi, WebRookie!<br>How on earth you get this code? <br>Try this code instead:<br>oleExcel.Range(&quot;C1&quot;).Select&nbsp;&nbsp;(assuming you want to insert a column prior to &quot;C&quot;)<br>oleExcel.Selection.EntireColumn.Insert
 
Oh my gosh...that's all i have to do?<br><br>I got that code from the macro i recorded in excel to insert two columns....but your code looks a lot easier.<br><br>May I ask how would I get all the properties and methods of OLE objects?<br><br>If I knew those it make life much easier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top