AOB
Well-known Member
- Joined
- Dec 15, 2010
- Messages
- 667
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
Bit of a weird one this...
I'm trying to generate an Excel table from an Access recordset and it's painfully slow for something that should, to my mind, be relatively quick.
I'm trying to sequence the order of operations to make it as efficient as possible, i.e. :
In other words, make the sequence as follows :
This works fine and you have a table structure with no styling/formatting. But when you then try to add styling at the end :
This throws an error :
On debugging, it seems that when the table is created, the
As soon as you clear the styling via
So when you then go to apply styling later on, it no longer recognises it as an object, and bugs out.
Which contradicts MS's documentation on the method as they imply you can just set the name the way I've described above - rather than documenting the actual object underlying it.
Seems weird behaviour and only thing I can think of is that you have to create a whole new
From what I can see here, once you purge the
I'm trying to generate an Excel table from an Access recordset and it's painfully slow for something that should, to my mind, be relatively quick.
I'm trying to sequence the order of operations to make it as efficient as possible, i.e. :
- Create the table (
ListObject
) - Add the data (
ListObject.InsertRowRange.CopyFromRecordset
) - Format the columns (
ListColumn.DataBodyRange.NumberFormat
based on the data type of each respective field in the recordset)
.ScreenUpdating
disabled) and then applying the style at the very end.In other words, make the sequence as follows :
- Create the table (
ListObject
) - Remove any default/pre-existing styling (make it plain)
- Add the data (
ListObject.InsertRowRange.CopyFromRecordset
) - Format the columns (
ListColumn.DataBodyRange.NumberFormat
based on the data type of each respective field in the recordset) - Apply a
TableStyle
with the relevant formatting, now that all the data and cell formatting is in place
VBA Code:
With lso
.Name = strTableName
.TableStyle = ""
End With
This works fine and you have a table structure with no styling/formatting. But when you then try to add styling at the end :
VBA Code:
With lso
.TableStyle = "TableStyleMedium16"
End With
This throws an error :
Error 438 : Object doesn't support this property or method
On debugging, it seems that when the table is created, the
ListObject.TableStyle
property is actually a layered object in and of itself, with several sub-properties (e.g. TableStyle.BuiltIn
, TableStyle.Creator
, TableStyle.Name
, TableStyle.Parent
etc.)As soon as you clear the styling via
ListObject.TableStyle
= "" it flattens to just a simple Variant/String
- it is no longer an object.So when you then go to apply styling later on, it no longer recognises it as an object, and bugs out.
Which contradicts MS's documentation on the method as they imply you can just set the name the way I've described above - rather than documenting the actual object underlying it.
Seems weird behaviour and only thing I can think of is that you have to create a whole new
TableStyle
object and set it - but if all you have to go off is the name, and none of the other properties, that's going to be messy.From what I can see here, once you purge the
ListObject
of any TableStyle
, it's lost to the ether and can't be recovered again - so how do you make a table "plain" while you work on it and then apply styles after the fact?