VBS Excel Insert Column issue

I have looked at many examples and have yet to find the solution to adding a column in Excel via a vb script.  Need some expert help on this one.  The code below is a small snippet of a larger problem but this is where it fails. The 5th line starting "selection" fails with and "Expected statement" error but i can't find a solution.  All I want to do is open the spreadsheet, go to column B and insert a column.  Simple but I can't get it to work.  If I record a macro I basically get the same code and it works as a macro but not in a VB script.  What am I missing?

Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks. Open strSourceFileName
Set objSheet = objExcel.ActiveWorkbook.WorkSheets(1)
Columns("B1:B1").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1").Select
RLESSORAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Use this....

Saurabh...

Set objexcel = CreateObject("Excel.Application")
objexcel.Workbooks.Open strSourceFileName
Set objsheet = objexcel.ActiveWorkbook.Worksheets(1)
objsheet.Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1").Select

Open in new window

0
DaveCommented:
or without select
Set objexcel = CreateObject("Excel.Application")
objexcel.Workbooks.Open strSourceFileName
Set objsheet = objexcel.ActiveWorkbook.Worksheets(1)
objsheet.Columns("B").EntireColumn.Insert

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Saurabh Singh TeotiaCommented:
Also one small changes in the later half..which is this...

With C1 you need to combine it with the sheet name...and combined the column as well without select...like dave suggested...

Saurabh...
Set objexcel = CreateObject("Excel.Application")
objexcel.Workbooks.Open strSourceFileName
Set objsheet = objexcel.ActiveWorkbook.Worksheets(1)
objsheet.Columns("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
objsheet.Range("C1").Select

Open in new window

0
RLESSORAuthor Commented:
Five minutes was awesome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.