Problems with Setting Properties for an Excel Object in Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am creating Excel reports out of access, and then reformatting the Excel
File when in Access. This works great and I have had much success.

However, I am trying to set the ShrinkToFit property on 2 columns and it is
not setting this property to true.

The following code correctly sets the WrapText property, but does not set
the ShrinkToFit property.

Set xlObject = CreateObject("excel.application")
Set xlbook = xlObject.Workbooks.Open(path_filename)
xlObject.worksheets(Sheet_Name).Activate
With xlObject
.range("C:C").select
.Selection.wraptext = True
.Selection.ColumnWidth = 22
.range("D:D").select
.Selection.ShrinkToFit = True
.Selection.ColumnWidth = 25
End With

Any help would be appreciated!
Thanks!
 
I'm assuming that if you set the ShrinkToFit to true, as you do, and
then set the ColumnWidth to a specific size (25) which you also do,
then the ShrinkToFit is re-set to False. You did tell the program to
make the column 25, which should negate the ShrinkToFit.
 
Removing the setting of the columnwidth has no affect. The shrinktofit
property is still not updating to True.
 
Automation is wonderful but it's easy to lose focus. You're asking
for help with an Excel issue in an Access newsgroup. :-)

HTH
 
Back
Top