Category: Snippets

  • Export VBA Modules for Version Control updated September 2024

    Export VBA Modules for Version Control updated September 2024

    Add a Module in your VBA Project. Name it “Exports” and paste the following code into the module in its entirety. When your project is ready for export (and subsequent version control), click on the “Macros” button in the Developer ribbon, select “ExportVBAModules” and click “Run.” Option Explicit ‘ Define a constant for the export…

  • Update Access VBA Saved Imports Exports: A Step-by-Step Guide

    Updating Access VBA saved imports exports is essential when dealing with external data sources. This step-by-step guide will show you how to update Access VBA saved imports exports by dynamically changing the file path within your import/export specifications. In this article, we’ll walk through a powerful VBA script that allows you to update Access VBA…

  • ReturnName

    Function ReturnName(ByVal num As Integer) As String ReturnName = Split(Cells(, num).Address, “$”)(1) End Function

  • DeleteInitialColumnsFromWorksheet

    Note: This function depends on ReturnName Sub DeleteInitialColumnsFromWorksheet( _ ws As Worksheet, _ NumberOfColumns As Integer _ ) With ws .Columns( _ ReturnName( _ 1 _ ) & _ “:” & _ ReturnName( _ NumberOfColumns _ ) _ ).Delete _ Shift:=xlToLeft End With End Sub

  • GetFilePath

    Public Function GetFilePath( _ sFullFileNameWithPath As String _ ) As String Dim fs As Object Set fs = CreateObject(“Scripting.FileSystemObject”) GetFilePath = _ fs.GetAbsolutePathName( _ sFullFileNameWithPath _ ) End Function

  • GetFileNameFromFullPath

    Public Function GetFileNameFromFullPath( _ sFullFileNameWithPath As String _ ) as String Dim fs As Object Set fs = CreateObject(“Scripting.FileSystemObject”) GetFileNameFromFullPath = _ fs.GetFilename( _ sFullFileNameWithPath _ ) Set fs = Nothing End Function

  • GetBaseName

    Public Function GetBaseName( _ sFullFileNameWithExtension As String _ ) Dim fs As Object Set fs = CreateObject(“Scripting.FileSystemObject”) GetBaseName = _ fs.GetBaseName( _ sFullFileNameWithExtension _ ) Set fs = Nothing End Function

  • TransferFontProperties

    TransferFontProperties

    Public Sub TransferFontProperties( _ rngSource As Range, _ rngTarget As Range _ ) Dim sf As Font Set sf = rngSource.Font With rngTarget.Font .Name = sf.Name .Size = sf.Size .Strikethrough = sf.Strikethrough .Superscript = sf.Superscript .Underline = sf.Underline .Color = sf.Color .Italic = sf.Italic .TintAndShade = sf.TintAndShade .Subscript = sf.Subscript .Bold = sf.Bold End With…

  • TrimRange

    TrimRange

    Public Function TrimRange( _ rngSource As Range, _ Optional TrimTop As Integer = 0, _ Optional TrimBottom As Integer = 0, _ Optional TrimLeft As Integer = 0, _ Optional TrimRight As Integer = 0 _ ) As Range Set TrimRange = _ rngSource.Offset( _ rowoffset:=TrimTop, _ columnoffset:=TrimLeft _ ).Resize( _ rngSource.Rows.Count – TrimTop -…

  • VBComponentNameIsUnique

    VBComponentNameIsUnique

    Public Function VBComponentNameIsUnique( _ wb As Workbook, _ strInputName As String _ ) As Boolean Dim vbc As VBComponent VBComponentNameIsUnique = True For Each vbc In wb.VBProject.VBComponents If vbc.Name = strInputName Then VBComponentNameIsUnique = False End If Next vbc End Function