Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Support importing library references #11

Merged
merged 23 commits into from
Jan 14, 2017
Merged

Support importing library references #11

merged 23 commits into from
Jan 14, 2017

Conversation

mattpalermo
Copy link
Collaborator

This branch (references) is based upon my json branch since it requires the json format for specifying references in the configuration file.

Library references (for example to the extensibility library) are
removed from an Excel file if the file is saved with no VBA code
in it. This may happen when using this add-in since all of the VBA
code is probably going to be exported before save. To solve this,
the add-in can now automatically inject references to libraries
when the user calls the import action. The details of the libraries
are declared in the configuration file. When the configuration
file is automatically generated, it will read the library references
which are currently referenced and list all the appropriate details
in the configuration file.

The "References" property of the configuration file is to be an
array of objects. Each object represents a library reference with
the following properties:

  • Name - name of the library
  • Description (optional) - description of the library
  • GUID - the GUID of the library
  • Major - the major version number of the library
  • Minor - the minor version number of the library
  • Path - The path to the library on the file system

If the GUID property is given then the GUID, Major and Minor
properties are used to locate the library, otherwise the Path
property is used.

Sorry about a slightly messy diff. I also did a small amount of refactoring on the functions I was working on.

See issue #4 and #5. This commit presents a solution which I think
is simple and appropriate.

#4
#5

The screenshot was removed because it is no longer relavent.
Perhaps @spences10 can make a new one :)
I hope these instructions are clear
To make development easier, I set up a template Excel file.
This Excel file is blank and has references to the nessesary
libraries set already. To build the Add-in, open the template
file and then import the files listed in the CodeExportFileList.conf
(perhaps using a version of this tool already installed).

Note that I have had to leave an empty module in the template file
because Excel will delete the library references without it.
This may be a problem to address with this tool.
My own decision bite me faster than I expected. I decided to
add the template file to the gitignore file so that people
wouldn't accedientally commit changes to it. Turns out that
loosing work is worse then commiting mistakes.
The project was being renamed in the MakeFileList method. This
was for historical reasons which now don't apply. The project name
should be set at build time, not at run time.
If the Add-In is password protected it can't be accidentally
edited in the VBE. This will keep you sain.
The project name was left as the default. This resulted in the
built add-in having the default project name. This change fixes
that.
The rubberduck VBA IDE code inspection tool shows possible problems
with VBA code. Using this a few bits of the code was improved.

* Accessors (Public / Private) were explicitly stated.
* Procedure parameters / arguments "pass by" types were explicitly
  stated.
* The use of the Is keyword was removed as it will most likely confuse
  others.
* Some unused variables and procedures were removed.
* Short variable names were replaced with more descriptive names

I tried to apply a consistent code style based on the existing
code style.
Previously, the format used for the config file was a simple
list of key-value pairs which was represented in a text file using
line breaks and colons. Additionally, square brackets had special
meaning as well. Even for this simple serialization requirement,
there was already a lot that the developer has to think about.
For example there was a function which cleaned out strings to make
sure the didn't break the serialization.

A feature which will be implemented soon would be a lot easier
to do if the config file was in a format such as JSON. Since
JSON is fairly easy to read and write it seems like it doesn't
introduce complexity. There is a popular open source VBA library
for reading and writing JSON called VBA-JSON. I used this library
and this simplified the data serialization code dramatically.

I changed a few details of how the actual importing and exporting
works, however there should be no loss of functionality.

Relative and absolute file paths should now be supported,
however I have not tested this yet. I have only tested the case
where all files are in the base directory.
Library references (for example to the extensibility library) are
removed from an Excel file if the file is saved with no VBA code
in it. This may happen when using this add-in since all of the VBA
code is probably going to be exported before save. To solve this,
the add-in can now automatically inject references to libraries
when the user calls the import action. The details of the libraries
are declared in the configuration file. When the configuration
file is automatically generated, it will read the library references
which are currently referenced and list all the appropriate details
in the configuration file.

The "References" property of the configuration file is to be an
array of objects. Each object represents a library reference with
the following properties:

* Name - name of the library
* Description (optional) - description of the library
* GUID - the GUID of the library
* Major - the major version number of the library
* Minor - the minor version number of the library
* Path - The path to the library on the file system

If the GUID property is given then the GUID, Major and Minor
properties are used to locate the library, otherwise the Path
property is used.
Add the required references to the configuration file and
remove Module1 from the template binary.
Since the add-in now deals with more than just code, it also
does references, some naming needs to be changed to reflect that.
@spences10
Copy link
Owner

This has the same issues as #10

image

😢

@Spence10 was having trouble importing the Dictionary.cls. The
VBA-Dictionary project has encountered this same problem before
and concluded that the problem was due to having Unix style line
endings in the VBA source files (especially class modules).

Firstly, a git attributes file was set up to make sure that VBA
modules are converted to windows style line endings. Secondly,
the use of the drop in Dictionary replacement is so that Excel
for Mac is supported. However, the Microsoft scripting library
is already used for file system purposes and therefore Mac isn't
supported anyway. So there should be no loss of compatibility by
using the Microsoft scripting library instead of the Dictionary
drop in replacement. The Dictionary class was removed.
Merge fix for problem with importing the Dictionary class.
@mattpalermo
Copy link
Collaborator Author

Ok, as with the json branch, I think this problem should be resolved now.

@spences10
Copy link
Owner

No still not able to import the class, I tried drag and drop and the manual process same with #10

@spences10 spences10 closed this Jan 14, 2017
@spences10 spences10 reopened this Jan 14, 2017
@spences10
Copy link
Owner

Sorry clicked wrong button 😕

@spences10 spences10 merged commit 2d9c512 into spences10:dev Jan 14, 2017
@spences10
Copy link
Owner

Great work @mattpalermo 👍 * 1000 👌

@mattpalermo mattpalermo deleted the references branch January 16, 2017 14:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants