enz_dducharme
New Member
- Joined
- Jun 22, 2017
- Messages
- 5
Hello,
I have a document that imports data from several files then exports it in a xlsx file without macros or formulas. I've been working on it for the past few years and generally didn't have any issues I couldn't figure out or solve myself. Naturally, this is a confidential work document so I am not comfortable sharing it. I would however like to know if anyone would be familiar with the issue I'm having:
At some point, I re-wrote a lot of code (for optimization and because we were experiencing issues occasionally) and although everything is much more efficient and fast now, my exported documents are much larger than they were before.
Now, before I say anything else, this is not an issue with the document being larger than I would like it to be. This is the reason I am asking this myself because people not understanding why their files are so large is all I could find. The difference with my issue is that my files usually are around 60 KB when exported but are now around 350 kb when exported... But if I close the document, open it again and just hit save, it goes back to 60 KB.
Now, to give a little context, 350 KB is an arbitrary number that depends on the amount of data that was imported. The document imports a lot of data, displays it in charts then on export keeps only calculation of the data (min, max, average etc.) converted to values and charts are converted to bitmaps. This results in files that would originally be over 1 MB drop to a consistent 50-60 KB.
I've tried going through my code or the changes I've made between when it saved with the correct size and when it saved it that "fake" size without success. My only solution that I absolutely hate was to include an extra bit of code that closes the document, opens it then saves it again... It doesn't take long at all to do so since the document is small but I feel horrible having something so stupid happening in my code. I would much rather solve the problem at its core.
Now my first assumption was that the charts somehow take more space than they should (which doesn't really make sense if the size lowers when I just save the document a second time). Here's the subroutine I use to convert all my charts to pictures:
(As a side note, this code doesn't work in my macro if I use .paste instead of ActiveWorkbook.Sheets("Report").Paste and I'm not sure why.) I've tried the method posted there too actually: https://www.mrexcel.com/forum/excel-questions/403172-convert-all-charts-worksheet-pictures.html and had the same result. Both will leave my document larger than it should be. I've tried have the macro only delete the charts and same thing.
I've changed my code from making a copy of the original workbook then deleting the raw data (only keeping the charts and values) to only copying what I want... And still the file is bloated.
I'm really not sure of what could cause this as it wasn't the case before. Has anyone ever had a similar issue?
I have a document that imports data from several files then exports it in a xlsx file without macros or formulas. I've been working on it for the past few years and generally didn't have any issues I couldn't figure out or solve myself. Naturally, this is a confidential work document so I am not comfortable sharing it. I would however like to know if anyone would be familiar with the issue I'm having:
At some point, I re-wrote a lot of code (for optimization and because we were experiencing issues occasionally) and although everything is much more efficient and fast now, my exported documents are much larger than they were before.
Now, before I say anything else, this is not an issue with the document being larger than I would like it to be. This is the reason I am asking this myself because people not understanding why their files are so large is all I could find. The difference with my issue is that my files usually are around 60 KB when exported but are now around 350 kb when exported... But if I close the document, open it again and just hit save, it goes back to 60 KB.
Now, to give a little context, 350 KB is an arbitrary number that depends on the amount of data that was imported. The document imports a lot of data, displays it in charts then on export keeps only calculation of the data (min, max, average etc.) converted to values and charts are converted to bitmaps. This results in files that would originally be over 1 MB drop to a consistent 50-60 KB.
I've tried going through my code or the changes I've made between when it saved with the correct size and when it saved it that "fake" size without success. My only solution that I absolutely hate was to include an extra bit of code that closes the document, opens it then saves it again... It doesn't take long at all to do so since the document is small but I feel horrible having something so stupid happening in my code. I would much rather solve the problem at its core.
Now my first assumption was that the charts somehow take more space than they should (which doesn't really make sense if the size lowers when I just save the document a second time). Here's the subroutine I use to convert all my charts to pictures:
Code:
Private Sub ChartsToBitmap()
Dim cht As ChartObject
For Each cht In Sheets("Report").ChartObjects
cht.CopyPicture xlScreen, xlBitmap
cht.TopLeftCell.Select
cht.Delete
ActiveWorkbook.Sheets("Report").Paste
Next cht
End Sub
(As a side note, this code doesn't work in my macro if I use .paste instead of ActiveWorkbook.Sheets("Report").Paste and I'm not sure why.) I've tried the method posted there too actually: https://www.mrexcel.com/forum/excel-questions/403172-convert-all-charts-worksheet-pictures.html and had the same result. Both will leave my document larger than it should be. I've tried have the macro only delete the charts and same thing.
I've changed my code from making a copy of the original workbook then deleting the raw data (only keeping the charts and values) to only copying what I want... And still the file is bloated.
I'm really not sure of what could cause this as it wasn't the case before. Has anyone ever had a similar issue?