xyzabc12341000
xyzabc12341000

Reputation: 15

How can I auto fit the columns in an access table through Excel vba

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

Answers (1)

Erik A
Erik A

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

Related Questions