spences10 / VBA-IDE-Code-Export

Export & Import VBA code for use with Git (or any VCS)
MIT License
120 stars 34 forks source link

When all VBA code is removed, library references are not saved #7

Closed mattpalermo closed 7 years ago

mattpalermo commented 7 years ago

I have found that library references don't persist when all the VBA code is removed. This could be annoying. Perhaps this tool can solve this problem by having a list of library references in the config file and then automatically inserting them when the code is imported. I would like to know what everyone thinks about this.

spences10 commented 7 years ago

Top idea @mattpalermo! Go ahead if you want

mattpalermo commented 7 years ago

Alright, I have done some research into the necessary API. Looks like this function will do the trick. Seems easy except for dealing with the config file. Looks like we will need to store the GUID, major and minor values in the config file. I would also like to store the name and description of the reference along side the other values to clarify the GUID for human readers. So that is 3 strings and 2 Long values. How should this be formatted in the configuration file?

I was thinking about changing the config file format to JSON and using the VBA-JSON library. This is a fairly big change, but it does have the advantage that it off-loads all future worry about data serialization to a pre-built solution. In my opinion JSON is not too bad to edit by hand (better than XML at least), but that may be because I have been recently using Javascript. What do you think? Is this overreacting? Is there a simpler solution?

Note: The same creator as VBA-JSON has also created VBA-XML.

spences10 commented 7 years ago

As long as the potential user can use it as a pure VBA experience [i.e. no need to install any software] then I'm all in. The idea is that this can be used by small teams that may not have admin rights on their machines and need to go cap in hand to admin to get a dependency installed

mattpalermo commented 7 years ago

The VBA-JSON library is just a VBA code module. I have been doing some more reading and realised that late binding is a much more robust and stable way of linking to external libraries. Sorry for all the fuss but I don't think I'll pursue this for now. Rather, I will try to implement late binding such that setting the library references is not needed.

spences10 commented 7 years ago

:+1:

mattpalermo commented 7 years ago

Update: Late binding doesn't work with the WithEvents keyword (used in the VBACmdHandler class). In this case, early binding is the only option. Additionally it seems that the general consensus is that the GUID of the extensibility library is fairly stable and there shouldn't be a problem with the portability of the reference. So I now see that there may be plenty of cases where early binding is the better option. And I have encountered one of those cases in the VBACmdHandler class. I will resume my effort of implementing the import and export of library references.

mattpalermo commented 7 years ago

Problem solved by #11

spences10 commented 7 years ago

Looks like this is still an issue, what was the reasoniong behind this again @mattpalermo

image

Was it just to have a completely empty project?

mattpalermo commented 7 years ago

Ah yes. My reasoning for this is not clear. Initially there was the problem that when all the modules were removed, the references would be removed by Excel. The user would then have to re-add them manually. So, to fix this, I made it so that references will be automatically added from the configuration file when the import happened. For exporting, I thought it was good idea to remove the references which would be added back when the import happened, therefore mimicking the behavior of the modules.

mattpalermo commented 7 years ago

I see you have an error in this section. Could you show the references section of the configuration file you are using? It appears that Excel refuses to remove MSForms. If that is the case, then perhaps MSForms shouldn't have to be in the configuration file.

spences10 commented 7 years ago

It's msforms in the immediate

On Tue, 31 Jan 2017, 04:06 Matthew Palermo, notifications@github.com wrote:

I see you have an error in this section. Could you show the references section of the configuration file you are using? It appears that Excel refuses to remove MSForms. If that is the case, then perhaps MSForms shouldn't have to be in the configuration file.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/spences10/VBA-IDE-Code-Export/issues/7#issuecomment-276270118, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOU1L7mVrf-VR2PkA4_n7S5BjSXNfJjks5rXrNTgaJpZM4LgZbp .

-- Regards, Scott Spence 07960 86 3382

mattpalermo commented 7 years ago

I see what is happening now. The solution is to add "MSForms" to the "blacklist" here: https://github.com/spences10/VBA-IDE-Code-Export/blob/6eedda7a7b11e0525f80ceb742b2899b39a4c0fe/modImportExport.bas#L91

I'll get onto this sometime today.

mattpalermo commented 7 years ago

PR #46 should fix this problem. The PR was pulled into the dev branch. It solved the problem for me and I think it will solve your problem as well. You may have to manually delete the MSForms entry from the configuration file.