{"id":35,"date":"2019-04-03T23:47:24","date_gmt":"2019-04-03T23:47:24","guid":{"rendered":"https:\/\/keithratner.live\/optionexplicit\/?p=35"},"modified":"2026-04-30T01:18:47","modified_gmt":"2026-04-30T01:18:47","slug":"export-modules-to-folder","status":"publish","type":"post","link":"https:\/\/keithratner.live\/optionexplicit\/export-modules-to-folder\/","title":{"rendered":"Export Modules to Folder"},"content":{"rendered":"<p>This will create a folder using the base name of your Excel file, which is the filename without its extension, along with a <b><code>vba<\/code><\/b> subfolder. Your VBA modules will be placed there. Pass <code>UseTimestamp:=True<\/code> to put each export in its own timestamped subfolder so repeated runs don&#8217;t overwrite earlier exports.<br \/>\n<strong><em>Set Reference to Microsoft Visual Basic for Applications Extensibility<\/em><\/strong><\/p>\n<pre>Sub ExportModules( _\n    Optional PathToVBAModules As String = \"\", _\n    Optional UseTimestamp As Boolean = False _\n)\n    Dim objMyProj As VBProject\n    Dim objVBComp As VBComponent\n    Dim strExt As String\n    Dim strBase As String\n    Dim strTimestamp As String\n\n    Set objMyProj = Application.VBE.ActiveVBProject\n\n    If PathToVBAModules = \"\" Then\n        strBase = ThisWorkbook.Path & \"\" & GetBaseName(ThisWorkbook.Name) & \"\"\n        MakeFolder strBase\n\n        If UseTimestamp Then\n            strTimestamp = Format(Now, \"yyyymmdd_hhmmss\")\n            PathToVBAModules = strBase & \"vba_\" & strTimestamp & \"\"\n        Else\n            PathToVBAModules = strBase & \"vba\"\n        End If\n        MakeFolder PathToVBAModules\n    End If\n\n    For Each objVBComp In objMyProj.VBComponents\n        Select Case objVBComp.Type\n            Case vbext_ct_StdModule\n                strExt = \".bas\"\n            Case vbext_ct_ClassModule\n                strExt = \".cls\"\n            Case vbext_ct_MSForm\n                strExt = \".frm\"\n            Case vbext_ct_Document\n                strExt = \".txt\"\n            Case Else\n                strExt = \".txt\"\n        End Select\n\n        If objVBComp.CodeModule.CountOfLines > 0 Then\n            objVBComp.Export PathToVBAModules & objVBComp.Name & strExt\n        End If\n    Next\n\n    MsgBox \"Modules exported to \" & PathToVBAModules\nEnd Sub<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This will create a folder using the base name of your Excel file, which is the filename without its extension, along with a vba subfolder. Your VBA modules will be placed there. Pass UseTimestamp:=True to put each export in its own timestamped subfolder so repeated runs don&#8217;t overwrite earlier exports. Set Reference to Microsoft Visual [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":51,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[114],"tags":[148,151,130,145],"class_list":["post-35","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippet","tag-file","tag-folder","tag-vbe","tag-vbproject"],"krwpengineoptions-featuredonwpengineblog":"","jetpack_featured_media_url":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/4-4-2019-2-16-36-AM.png?fit=665%2C496&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pgsIIA-z","jetpack-related-posts":[{"id":563,"url":"https:\/\/keithratner.live\/optionexplicit\/update-access-vba-saved-imports-exports\/","url_meta":{"origin":35,"position":0},"title":"Update Access VBA Saved Imports Exports: A Step-by-Step Guide","author":"Keith","date":"May 3, 2024","format":false,"excerpt":"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\u2026","rel":"","context":"In &quot;Article&quot;","block_context":{"text":"Article","link":"https:\/\/keithratner.live\/optionexplicit\/category\/article\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2024\/05\/Screenshot-2024-05-03-133800.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":52,"url":"https:\/\/keithratner.live\/optionexplicit\/notes-on-style-vba-coding-style\/","url_meta":{"origin":35,"position":1},"title":"Notes on VBA Coding Style: Maximizing Scalability and Readability","author":"Keith","date":"April 4, 2019","format":false,"excerpt":"Establishing and adhering to a VBA coding style guide enables increased project reusability and scalability. It makes code more readable and, by extension, the coding experience far more enjoyable. Minimize Horizontal Scrolling Split lines (use the underscore!) and indent. My rationale is that horizontal scrolling takes too long. You want\u2026","rel":"","context":"In &quot;Article&quot;","block_context":{"text":"Article","link":"https:\/\/keithratner.live\/optionexplicit\/category\/article\/"},"img":{"alt_text":"Notes on Style","src":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/notes-on-style.png?fit=724%2C962&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/notes-on-style.png?fit=724%2C962&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/notes-on-style.png?fit=724%2C962&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/notes-on-style.png?fit=724%2C962&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":65,"url":"https:\/\/keithratner.live\/optionexplicit\/deleteallfilesinfolder\/","url_meta":{"origin":35,"position":2},"title":"DeleteAllFilesInFolder","author":"Keith","date":"April 4, 2019","format":false,"excerpt":"Public Sub DeleteAllFilesInFolder( _ strPathToFolder As String _ ) Dim _ fs As Object, _ fldr As Object, _ f As Object Set fs = CreateObject(\"Scripting.FileSystemObject\") Set fldr = fs.GetFolder(strPathToFolder) For Each f In fldr.Files Application.StatusBar = _ \"Deleting file \" & _ f.Name & _ \" from folder \"\u2026","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"DeleteAllFilesInFolder","src":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/deleteallfilesinfolder.png?fit=389%2C343&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":175,"url":"https:\/\/keithratner.live\/optionexplicit\/folderexists\/","url_meta":{"origin":35,"position":3},"title":"FolderExists","author":"Keith","date":"July 8, 2019","format":false,"excerpt":"Function FolderExists( _ strCompleteFolderPath As String _ ) As Boolean Dim _ fs As Object Set _ fs = _ CreateObject( _ \"Scripting.FileSystemObject\" _ ) FolderExists = _ fs.FolderExists( _ strCompleteFolderPath _ ) Set _ fs = _ Nothing End Function","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":81,"url":"https:\/\/keithratner.live\/optionexplicit\/elapsedtime\/","url_meta":{"origin":35,"position":4},"title":"ElapsedTime","author":"Keith","date":"April 8, 2019","format":false,"excerpt":"Function ElapsedTime( _ endTime As Date, _ startTime As Date _ ) As String Dim Interval As Date ' Calculate the time interval. Interval = endTime - startTime ' Format and print the time interval in ' days, hours, minutes and seconds. ElapsedTime = _ Int( _ CSng( _ Interval\u2026","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/elapsedtime.png?fit=309%2C480&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":72,"url":"https:\/\/keithratner.live\/optionexplicit\/renderlistcontrolheadings\/","url_meta":{"origin":35,"position":5},"title":"RenderListControlHeadings","author":"Keith","date":"April 7, 2019","format":false,"excerpt":"Public Sub RenderListControlHeadings( _ ListControl As Control, _ ColumnHeadingString As String, _ Optional FontWeight As Long = 400, _ Optional OffsetLeft As Long = 8 _ ) Dim ctls As Controls Dim iCtl As Control Dim strControlNameStub As String Dim strLabelNameStub As String Set ctls = ListControl.Parent.Controls strLabelNameStub = \"lbheading_\"\u2026","rel":"","context":"In &quot;Snippet&quot;","block_context":{"text":"Snippet","link":"https:\/\/keithratner.live\/optionexplicit\/category\/snippet\/"},"img":{"alt_text":"RenderListControlHeadings","src":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/renderlistcontrolheadings.png?fit=576%2C1008&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/renderlistcontrolheadings.png?fit=576%2C1008&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/keithratner.live\/optionexplicit\/wp-content\/uploads\/sites\/29\/2019\/04\/renderlistcontrolheadings.png?fit=576%2C1008&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":11,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":1519,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/posts\/35\/revisions\/1519"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/media\/51"}],"wp:attachment":[{"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keithratner.live\/optionexplicit\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}