Reputation: 15
So basically I've created a macro to format a sheet in a certain way and I've got a code which exports and stores this info in an access database.
The thing is that the columns are the default size and not auto fitted. How can I auto fit the columns in access through Excel vba. I've tried googling and searching online but I can only seem to find formats from access to Excel. Not Excel to access. Any help would be appreciated.
Thanks
Upvotes: 1
Views: 2236
Reputation: 32642
Access tables don't support autofit.
You can influence column width in Access through CurrentDb.TableDefs("TableNameOrNumber").Fields("FieldNameOrNumber").Properties!ColumnWidth
.
However, the common value for autofit, -2, doesn't work for this property, and just sets it to the default width.
That means you have to calculate the width of a certain table column, or copy the width from Excel if you're using identical font settings.
Upvotes: 3