I have created a macro that uses multiple modules, class modules, and forms. I am looking for a way to bundle install all these files to the Project Global Template (Global.MPT) without having to manually adding each file through VBA ide. Does anyone know a good solution to this issue? Thanks!
The application method OrganizerMoveItem can be used to copy modules, class modules, and forms (also tables, views, etc) from one project to another, including the global.mpt file.
Here's an example:
Application.OrganizerMoveItem pjModules, ThisProject.Name, "global.mpt", "frmTest", False
Also try searching SO for other questions about ms project global file.
Related
I am writing a very basic library in VB.NET
The library just contains classes and modules.
Now in built output I see this files
Application.Designer.vb
Application.myapp
AssemblyInfo.vb
Resources.Designer.vb
Resources.resx
Settings.Designer.vb
Settings.settings
Since I've seen other libraries with only AssemblyInfo.vb file, I was wondering if I can delete the rest.
What is the minimum of files I need here for the lib to work correctly, since I don't have any ressource or setting?
All the files you listed are necessary for a vb.net library project. And these files are generated (in My Project folder) when the project created not the build output files. So you need to keep all the files you listed in order to develop and build your project locally.
And for the files of build output, you can add these files in .gitignore.
When you create a project in VS, you select a predefined template that dictates what gets created. People often become accustomed to seeing the superfluous objects that a given template creates and assume that those objects are mandatory and must be there, However, much of it is not needed.
There is also the Empty Project template (the exact name of this template varies depending on the VS version used).
In VS2017, selection of the template would look like this:
This is a bare-bones project and the Solution Explorer will look like this:
As you can see, there are no pre-loaded references. You will need to add them yourself. About the only thing defined in this template is that you are using the VB language; This project starts out as a WinForm type, so go to the Project Properties->Application tab and change the "Application type" to "Class Library" since you want to create a library.
You may find it useful to start with an Empty Project and add the stuff you normally use and then export the project as new template (in VS2017: Project Menu->Export Template). For more on creating termplates, see: Creating Project and Item Templates
Edit: I just realized that I did not answer your real question about deleting the unused items. I just did a test case and deleted the items under MyProject. I received an error on deletion, but doing a clean/rebuild allowed me to proceed without issues. I would recommend that you backup the project before attempting this on an existing project, but I saw no long term issues in deleting unneeded objects from MyProject.
I have a large project in VBA with lots of functionality that I would like to use in my program. When I run the program I get this
How can I make the prjGlobalPPT a part of VBAProject?
You need to refer to the project explicitly:
Application.Run prjGlobalPPT.ADV_UpdateChart
I found the solution. I had to include prjGloabalPPT by filling in the properties under Tools.
I have 2 distinct VBA projects that make use of 8 identical classes.
If i export those classes to a directory in my disk, is there a way to instantiate them programatically to avoid code duplication?
I don't see any problem by having the same code in 2 distinct projects, but my boss asked if it is possible and so far i haven't found anything that could lead me to an answer in the microsoft online help and in some books i've got.
Now that I understand your question, a central library of sorts may be your best option, there are others but I'm always a fan of libraries.
To achieve this:
Create a new workbook, import all of your class modules in to the VBA project in that workbook. Name your project something like MyCentralLibrary (something different than VBAProject)
Set the class module's Instancing Property to PublicNotCreatable
(change this in the properties window)
Now here comes the slightly
stupid part (I never was a fan of VBA). Projects referencing this
library will be able to see all the classes but never instantiate a
new instance of them. So what you'll have to do is for each class you put in the library,
write a function with the class as the return type, like so:
Public Function GetMyClass() As MyClass
Set GetMyClass = New MyClass
End Function
Now in the project you want to reference your central library. Go to Tools -> References and choose your library name from the list. Now you can instantiate classes from that library in your project like so:
Public c As MyCentralLibrary.MyClass
Set c = MyCentralLibrary.GetMyClass()
Again, there's other ways of doing it, but I'm always a proponent of libraries (at least in other languages)
As a note, if/when you move between computers,, you'll obviously have to move the workbook with your library in it around and re-do the references for any projects referencing the library on the new computer.
My two cents, if this were to scale more I'd go ahead and grab the free version of Visual Studio and turn this into a class library that can be referenced from Excel. But that's just me and my dislike of VBA shining through ;).
Yes, it is possible, but you have to change some security settings. I do something similar to this in all my VBA projects so I can use source control.
The code to import a class module into your project would be
ThisWorkbook.VBProject.VBComponents.Import "C:\path\to\myclass.cls"
In order for this to work, you have to change your security settings to allow access to the VBA project object model. This is because in the past some viruses has spread via this mechanism. The setting is in File > Options > Trust Center > Trust Center Settings... > Macro Settings > Trust access to the VBA project object model.
As a workaround I exported the methods in those classes to a DLL file and saved it in the server. Whenever the user opens the .xlsm file, a method is called to register the DLL in their computers and then I can use the methods and properties contained in it without further problems.
I also considered the other answers to this question. But sending 2 files (one that contains the datasheet that will be used and another one for the library) would not be a good idea (users would not understand what is the reason for that) because those programs will be used by a lot of users.
I develop quite complex Excel VBA application (several thousands lines of code spread across modules, class modules and form modules). There is a need to translate it to multiple languages, which means to replace (almost) all of the strings in application and use some kind of hash-table with records for each language.
My question is what is the most efficient and convenient way to gather all strings used in application and replace them with some kind of language variables. Could anybody recommend some kind of best practices for this type of task for VBA project environment? Thanks in advance.
One option is to use source tools addin to export all your code into source files under one folder. Example below:
Now you can write scripts to modify the files, and also now you can put them in source control. When done you can re-import them into the VBA project with changes.
I'm working on an big excel-addin with many modules. I need to export them to .bas file to manage them with SVN. I know a hot key to export them fast, Ctrl+E. But the number of my modules is too many that I still lose too much time to export them.
Does anyone know a faster way to do this?
This is a great tool which should do what you need
http://www.appspro.com/Utilities/CodeCleaner.htm
From their website:
Export Code Files - This feature allows you to export all the code files from a project to the directory you specify without the need to perform a project cleaning.
If you are having trouble locating the menu option, see the above page for information:
You must set your security to trust access to Visual Basic projects in order to use the code cleaner.
In Excel 2007 the code cleaner can only be run from the VBE Tools menu. There will be no option to run the code cleaner from the new Excel 2007 Ribbon user interface.