VBA-IDE-Code-Export
VBA-IDE-Code-Export copied to clipboard
New empty lines added to .frm file after import then export
I am finding that a new line is added after the Attribute header each time I do a Import then Export cycle. I view the .frm file in a text editor and watch the file grow as I import then export over and over. Does anyone else suffer from this?
Related bug report: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_windows8/excel-vba-bug-importing-a-form-adds-a-newline-at/f8901ff1-68d1-40c5-b41d-4b87a0f9db8e
Ok, something I have never noticed before, may have had it happen but never noticed really. This can be problematic for this situation though, maybe we could use some of the CodeModule functions?
Like the example here, a straight copy pasta from the modImportExport.bas
Set modCodeCopy = comNewImport.CodeModule
Set modCodePaste = comExistingComp.CodeModule
modCodePaste.DeleteLines 1, modCodePaste.CountOfLines
If modCodeCopy.CountOfLines > 0 Then
modCodePaste.AddFromString modCodeCopy.Lines(1, modCodeCopy.CountOfLines)
End If
Project.VBComponents.Remove comNewImport
No, that's not going to work very well as you'd need to go through all the files
:thinking:
I'll come back on this
Argh, I must has glossed over that part at some point and left it out. Worth a try.
Oh, actually I withdraw that comment. It is still there https://github.com/spences10/VBA-IDE-Code-Export/blob/6eedda7a7b11e0525f80ceb742b2899b39a4c0fe/modImportExport.bas#L276
But yes, maybe there is a hack using CodeModule functions that we could conjure up to solve this problem.
Yeah, it's going to be some ugly loop through all modules, check for whitespace which will seem overkill but either that than have 15,000 empty lines at the start of your code I guess
I think the thing with this is that in the most part it's a straight import export with forms, why change it gah! Annoying!!
We have to do a whole new thing, to get around an annoying thing, thanks Microsoft
Yes. In the mean time, it can be fixed using a text editor. I usually try to check the git diff before committing and touch up the whitespace with a text editor if needed. I do this as a routine to remove trailing whitespace as well.
Thoughts about implementation: The whitespace is added between the attributes and the rest of the code. The attributes "header" seems quite different from the rest of VBA syntax so it seems possible that we could identify the end of the attributes section automatically and simply remove whitelines before the first non-whiteline.
This could be part of a grander "formatting" code which also removes trailing whitespace (this would be quite useful).
Edit: May be useful to look at VBADeveloper's formatting code for inspiration.
We hit this bug in the Rubberduck project a while back. You may want to browse our source to see how we handled it. If you have trouble finding it, let me know and I'll lend a hand.
Hi @rubberduck203 thanks for taking a look, @mattpalermo I'll let you take a look at this one if you know what needs doing??
Thankyou @rubberduck203 for this. I'll definitely have a look.
Not sure if it's still relevant, but this is the relevant code in Rubberduck:
https://github.com/rubberduck-vba/Rubberduck/blob/2b341dd15605cbca037f3d5f7c50ef83fedc7c3b/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBComponents.cs#L133-L150
Note that this creates another problem - member attributes get wiped out, since the module isn't really imported, but re-written. You'll need another mechanism in place to avoid losing the member attributes (we've fixed that as well in Rubberduck, but that's pretty involved).