Using VB6 and OLE to add a new column to an existing Excel worksheet

  • Thread starter Thread starter canoe414
  • Start date Start date
C

canoe414

Greetings,

Is it possible to programmatically add a new column to an existing
Excel worksheet using VB 6.0 and OLE? Or VB 6.0 and ??? It's OK if the
added column becomes the new "A" column and shifts all previously
existing columns over one. I 'haven't been able to google up any
coding examples that do this. Examples are always welcome.

TIA,

Steve
 
Sub addcolum()
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object

Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open("C:\myDir\myBook.xls") '<=== change to
suit
Set xlWS = xlWB.Worksheets(1)
xlWS.Columns(1).Insert

Set xlWS = Nothing
Set xlWB = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Thanks that seems to have worked. I mean, my app now runs to completion
without errors and does create a new .xls - but I can't open it with
Excel to view it!! Any idea what could cause this behavior?

Thanks for your previous help!


Steve
 
can you clarify what you mean, detail the steps that you took.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Greetings,

Is it possible to programmatically add a new column to an existing
Excel worksheet using VB 6.0 and OLE? Or VB 6.0 and ??? It's OK if the
added column becomes the new "A" column and shifts all previously
existing columns over one. I 'haven't been able to google up any
coding examples that do this. Examples are always welcome.

TIA,

Steve

Check here, maybe this is what you are asking for:
http://support.microsoft.com/kb/285332

Check References within that article for more links.

Dmitriy.
 

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

Back
Top