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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RE: Excel Automation Column Widths

Status
Not open for further replies.

AaronA

Programmer
Sep 27, 2000
21
US
I am trying to do some Excel Automation. I need to be able to change the width of a column in the Excel Workbook. Any Ideas on how to do that? I have tried this:

Workbook.Range("A1").Width = 12

do you see what I am trying to do? It tells me something about an object is required, but I am trying to set a number, not an object. I have also tried using the column property, but gives an error as well. Hope someone can help. Thanks
 
Range is an object that requires you to asign something to it.
Use following code:

pobjExcel.Worksheets("Sheet1").Columns("B").ColumnWidth = 30

pobjExcel is a variable containing reference to excel.application. Be careful using global code i.e. just writing worksheets without the preceding variable. It will work the first time but if you are doing anything in a loop it will error out on subsequent tries.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top