Solved

Using a central macro base for all users

Posted on 2013-11-25
6
139 Views
Last Modified: 2013-12-13
I generate workbooks for the timesheets of each staff member from a master workbook. This generated workbook contains some macros. Whenever I add/update the macros they are available for the staff in the following month only. I was wondering if there could be a system wherein each of the generated workbook contains a caller macro which calls a central macro in a file residing on the server so that any changes done during the month are immediately affected to all workbooks.

PS: All macros are event-fired. None of them are user-invoked. The events at the moment are worksheet_change and worksheet_selectionchange but may have to be expanded.
0
Comment
Question by:Saqib Husain, Syed
  • 3
  • 3
6 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39674429
Hi,

you could create an XL add-in with all procedures

refer all the events to the add-in subs, for the ones you don't yet use,  keep an empty sub

to call the add-in

 
Sub MyTest() 
    Application.Run ("myaddin.xla!mySelectionChange") 
End Sub 

Open in new window

Regards
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39679839
Is there a way for a macro to install/update the addin? I do not want to go myself to install the addin on all computers. Some people bring their own laptop and I might not be available to do the installation.
0
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39680002
Hi,

you could send your user a file with this code to install an add in

as workbook_open code

Sub CheckAndInstall()
   
    myAddInName = "Addin Name"
    File = "S:\AddinLocation\myAddin.xla"
    
    On Error Resume Next
    Result = AddIns(myAddInName).Installed
    On Error GoTo 0
                                            
    If IsEmpty(Result) Then
        Set myAddin = Application.AddIns.Add(Filename:=File)
        myAddin.Installed = True
        Application.AddIns(myAddInName).Installed = True
    ElseIf Application.AddIns(myAddInName).Installed = False Then
        Application.AddIns(myAddInName).Installed = True
    End If
End Sub

Open in new window


and then in the add-in this code (I've changed my mind on how to change the code)

Private Sub Workbook_Open()
    'rename the module
    ThisWorkbook.VBProject.VBComponents("Module1").Name = "ModuleTemp"
    'remove the module
    ThisWorkbook.VBProject.VBComponents.Remove ThisWorkbook.VBProject.VBComponents("ModuleTemp")
    'Import the module
    ThisWorkbook.VBProject.VBComponents.Import ("f:\GlobalCode\Module1.bas")
    ThisWorkbook.VBProject.VBComponents(ThisWorkbook.VBProject.VBComponents.Count).Name = "Module1"
        

End Function

Open in new window

Regards
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39680058
Hi, Thanks for the effort. The looks are now good. But it is going to take e some time to test it. Please bear with me while I get the time to test it.

Saqib
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39680081
Hi,

if do not want to have your add-in centrally saved you could use

MsgBox Application.StartupPath

to get the startup folder of each user

Regards
0
 
LVL 43

Author Closing Comment

by:Saqib Husain, Syed
ID: 39716013
Sorry, I could not test it but it is time to close this now,

Thanks for everything.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question