I am exporting a view to Excel via a button. This process works fine but I cannot seem to get my columns/rows to autofit in Excel. What is wrong with my code?
Set Excel = CreateObject( "Excel.Application" )
Excel.DisplayAlerts = False
Excel.Workbooks.Add
Excel.Visible = True
Excel.Columns.autofit
Excel.rows.autofit
numKeys = 1
Excel.Range("A"&numKeys).Select
Excel.ActiveCell.FormulaR1C1 = "Requester"
Excel.Range("A"&numKeys).Select
Excel.ActiveCell.FormulaR1C1 =doc.fld_DM_Requester(0)
Subject: Excel AutoFit - Can’t Get it to Work.
I’ve always applied autofit individually after filling in the table -
xlsheet.columns().Autofit
Works for me.
hcl-bot
January 11, 2006, 11:12am
3
Subject: Excel AutoFit - Can’t Get it to Work.
Two things:
You have to call autofit after the contents are in the approriate colums/rows (otherwise it doesn’t know how to resize)
You should use the ‘call’ keyword when appropriate.
E.g.:
Call Excel.Columns.autofit()
Call Excel.rows.autofit()
cheers,
Bram
Subject: Excel AutoFit - Can’t Get it to Work.
Hi Lemens,
Try using columns and rows range as shown below.
Excel.Columns(“A:L”).EntireColumn.AutoFit
Excel.Rows(“1:3”).EntireRow.AutoFit
Hope it helps !
Cheers
Vinit