Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:53:24+00:00 2026-05-31T11:53:24+00:00

What is the best way to avoid duplicating code when working in VBA? I’m

  • 0

What is the best way to avoid duplicating code when working in VBA?

I’m used to languages where I can just add an import statement and get access to all a class’s public properties and functions, so I can just create a utility class with some common functions and have access to that in any project I choose to import it to. Any time I want to update one of those functions, one edit is all it takes to get it working across all projects.

Is there any good way to replicate this functionality in VBA?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:53:25+00:00Added an answer on May 31, 2026 at 11:53 am

    What follows focuses on Excel but I am pretty sure the same would apply to any Office products.

    The easy way is to save your reusable code as an addin (*.xla for Excel 2003, *.xlam for Excel 2007+). You then add the addin to Excel and all the spreadsheets you open will have access to the custom functions you have in your addin. If you add specific VBA code to a spreadsheet, you can add a reference to your addin and your VBA code will have access to all the public sub, function and classes of your addin.

    In my organisation, we use 3 home made addins – they are stored in C:\Program Files\OrganisationName. And everybody has access to them. When an update is made, we only need to copy the new version to everybody’s hard drive and restart Excel and they have the new version.

    The addins contain utilities functions such as functions to:

    • read data from / write data to spreadsheets / files / databases.
    • usual data manipulation such as removing duplicates from a list
    • advanced statistical functions
    • etc.

    A few drawbacks:

    • If you have several instances of Excel open, only one can update the addin, the other instances are in read-only mode
    • If Excel crashes, the auto recovery mode generally does not save the changes you made on your addin (TBC on newer versions) – there are a few tools to auto save regularly

    An alternative is to develop xlls or COM libraries in VB or C# for example, but this is something I have not tried.

    There are plenty of tutorials online if you need a more detailed procedure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to avoid that an application is copied and used
What's the best way (to avoid modifying repeated code) to building multilingual web pages?
What's the best way to avoid hardcoding URL's in JavaScript (primarily used when making
I'm not sure what the best way to avoid duplicate markers on a Google
The best way I can think of to ask this is by example... In
What's the best way in C# to set up a utility app that can
The best way to avoid SQL injection for defined value type such as numbers,
What is the best way to avoid SQL injection on MSSQL Server from C#
What would be the best way to avoid SQL injection on the C#.net platform.
What is the best way to avoid \' while we get the values from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.