Lars,
I'm afraid this one won't go away. To make things work and avoid going back to version 4, I've modified the library code in a few places. These changes are probably not 100% correct and are workarounds, but seem to fix the problems we've had.
What seemed to be happening was that a defined name was being created when adding an autofilter and its value (FContent) was set correctly, but then when this name was being written to the sheet in OnWriteDefinedName, the line "Name.Content := N.Content;" was calling a get property on N (TXLSName.GetContent) which was ignoring the value stored in FContent and calculating a different value based on the area, which wasn't set.
Basically I've had to manually set the SheetName and dimensions of the FArea record of the TXc12DefinedName when adding an Autofilter, then force the name to be an area when running Compile.
In TXLSName.Compile, add the following if statement to the line setting FSimpleName:
Code: Select all
if FBuiltIn = bnFilterDatabase then
FSimpleName := xsntArea
else
FSimpleName := IsSimpleName(FParent.FManager,FPtgs,FPtgsSz,@FArea);
This is probably something that IsSimpleName should be doing but this was the quick fix.
In TXLSAutoFilter.Add add the following code to set the FArea values:
Code: Select all
N.SheetIndex := FXc12Sheet.Index;
N.Col1 := AC1;
N.Col2 := AC2;
N.Row1 := AR1;
N.Row2 := AR2;
In TXc12DefinedName, make the properties writeable:
Code: Select all
property SheetIndex: integer read FArea.SheetIndex write FArea.SheetIndex;
property Col1: integer read GetCol1 write FArea.Col1;
property Row1: integer read GetRow1 write FArea.Row1;
property Col2: integer read GetCol2 write FArea.Col2;
property Row2: integer read GetRow2 write FArea.Row2;
This code forces the defined name to use the correct sheet name and area values for its value, even on multiple tabbed workbooks.
Does any of the above look correct, or am I missing something else?
Thanks,
James