Export all VBA modules under Word
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Export all VBA modules under Word
Is there a way of exporting *all* modules, forms, class modules, etc. from a template to a folder? I am fed up of doing them one at a time.
Thanks.
Robie
Thanks.
Robie
-
- Administrator
- Posts: 78930
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Export all VBA modules under Word
Try this:
You can change ActiveDocument to ActiveDocument.AttachedTemplate, for example.
Code: Select all
Sub ExportAll()
Dim strPath As String
Dim vbc As Object
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
strPath = .SelectedItems(1)
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
For Each vbc In ActiveDocument.VBProject.VBComponents
vbc.Export strPath & vbc.Name & ".txt"
Next vbc
Else
MsgBox "No folder specified...", vbExclamation
End If
End With
End Sub
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Export all VBA modules under Word
That is fantastic Hans. Works like a charm and saved me a lot of time exporting each individual modules.HansV wrote:Try this:
You can change ActiveDocument to ActiveDocument.AttachedTemplate, for example.Code: Select all
Sub ExportAll() Dim strPath As String Dim vbc As Object With Application.FileDialog(msoFileDialogFolderPicker) If .Show Then strPath = .SelectedItems(1) If Right(strPath, 1) <> "\" Then strPath = strPath & "\" End If For Each vbc In ActiveDocument.VBProject.VBComponents vbc.Export strPath & vbc.Name & ".txt" Next vbc Else MsgBox "No folder specified...", vbExclamation End If End With End Sub
Thank you so much.
-
- NewLounger
- Posts: 1
- Joined: 11 Feb 2018, 18:47
Re: Export all VBA modules under Word
Hans, thank you soooo much for your code!
I've been looking for it for several days! It's cool (and so are you) !
I've been looking for it for several days! It's cool (and so are you) !
-
- PlutoniumLounger
- Posts: 15826
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Export all VBA modules under Word
Hi Robie.Robie wrote:Is there a way of exporting *all* modules, forms, class modules, etc. from a template to a folder? I am fed up of doing them one at a time.
Thanks.
Robie
Might one ask why you want to do this?
Cheers
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed
-
- 5StarLounger
- Posts: 641
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Export all VBA modules under Word
Don't know about Robie, but it is a quick way to back up the vba or transfer it. I have hundreds of macros I store in my normal.dotm in more than 10 modules. For the most part, they are never used from within the Word UI, but rather serve as the basis for code in other templates. Most are designated as "private" because I don't want them showing up in the macro lists.ChrisGreaves wrote:Hi Robie.Robie wrote:Is there a way of exporting *all* modules, forms, class modules, etc. from a template to a folder? I am fed up of doing them one at a time.
Thanks.
Robie
Might one ask why you want to do this?
Cheers
Chris
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- PlutoniumLounger
- Posts: 15826
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Export all VBA modules under Word
Agreed.Charles Kenyon wrote:... but it is a quick way to back up the vba or transfer it. ...
But I'd use Rob Bovey's Code Cleaner for such a simple task.
I was curious as to whether Robie had a greater need that might be solved by existing utilities.
Cheers
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed
-
- 5StarLounger
- Posts: 641
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Export all VBA modules under Word
Does it work in Word?ChrisGreaves wrote:Agreed.Charles Kenyon wrote:... but it is a quick way to back up the vba or transfer it. ...
But I'd use Rob Bovey's Code Cleaner for such a simple task.
I was curious as to whether Robie had a greater need that might be solved by existing utilities.
Cheers
Chris
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- PlutoniumLounger
- Posts: 15826
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Export all VBA modules under Word
Well, yes.Charles Kenyon wrote:Does it work in Word?
At least, I have a version that works in MSWord2003. I have made it kick in whenever a version of my template changes.
e.g. Going from Playr017.dot to Player018.dot, it asks me if i want to export/import the code (i usually do!).
''' VBA Code Cleaner 4.4 © 1996-2001 by Rob Bovey,
''' all rights reserved. May be redistributed for free but
''' may not be sold without the author's explicit permission.
Right now I can't find a copy on the web, but if you want a version of my downloaded Word copy PM me.
Cheers
Chris
P.S. One of these links might work.
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed
-
- 5StarLounger
- Posts: 641
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
-
- PlutoniumLounger
- Posts: 15826
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Export all VBA modules under Word
Thanks Charles.Charles Kenyon wrote:Found one here.
The one you found is (a) for Excel and (b) is a COM rather than an addin and (c) is for 232-bit only, right?
I am using one written in WordVBA, with the source visible - and hence adjustable - that runs in what I think is a 32-bit Word 2003. (Although Hans is waiting to set me straight on that claim(grin))
Cheers
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed
-
- Administrator
- Posts: 78930
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Export all VBA modules under Word
There is a Word Code Cleaner available at the bottom of the following page. It is based on the one for Excel.
Combatting Template Bloat
The page says that it works in Word 97, 2000 and 2002, but although I haven't tested it, I see no reason why it wouldn't work in more recent versions.
Combatting Template Bloat
The page says that it works in Word 97, 2000 and 2002, but although I haven't tested it, I see no reason why it wouldn't work in more recent versions.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 641
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Export all VBA modules under Word
I've tried to get Bill Coan's Code Cleaner to work but haven't been able to get it to do so. It is an .exe file. I no longer remember how to adjust .com Add-Ins on menu versions of Word. I've asked Chris to send me the vba one that he has via private message.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- Microsoft MVP
- Posts: 1320
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Export all VBA modules under Word
Charles, the Word Code Cleaner.exe file is just an installer made by (probably) PKZip. Rename it with a .zip extension and you can extract the contents: Word Code Cleaner.dot, Setup.doc, and Cleaner.hlp. All you really need is to extract the .dot file to the Startup folder, or use the Templates & Add-Ins dialog to add it to the current session. If you want to read the Cleaner.hlp file, you'll have to install the WinHlp program from https://support.microsoft.com/en-us/hel ... luded-or-h. To install it on Windows 10, you need the answer to https://answers.microsoft.com/en-us/win ... 8bed33265c.Charles Kenyon wrote:I've tried to get Bill Coan's Code Cleaner to work but haven't been able to get it to do so. It is an .exe file. I no longer remember how to adjust .com Add-Ins on menu versions of Word. I've asked Chris to send me the vba one that he has via private message.
-
- 5StarLounger
- Posts: 641
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Export all VBA modules under Word
Thank you Jay. I extracted it and the commands show up under the Add-In tab.
I converted it to .dotm and added a QAT button.
I converted it to .dotm and added a QAT button.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- PlutoniumLounger
- Posts: 15826
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Export all VBA modules under Word
Charles Kenyon wrote:...a QAT button.
Cheers
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed
-
- Administrator
- Posts: 78930
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Export all VBA modules under Word
QAT = Quick Access Toolbar, a feature in the ribbon version of Office applications.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- PlutoniumLounger
- Posts: 15826
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Export all VBA modules under Word
HansV wrote:QAT = Quick Access Toolbar, a feature in the ribbon version of Office applications.
Oh.
One of the features in this new-fangled version of MS-Word.
Ta ever so.
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Export all VBA modules under Word
Sorry, coming bit late to this. Have been away and not well after the holidays.ChrisGreaves wrote:Hi Robie.Robie wrote:Is there a way of exporting *all* modules, forms, class modules, etc. from a template to a folder? I am fed up of doing them one at a time.
Thanks.
Robie
Might one ask why you want to do this?
Cheers
Chris
I only wanted a copy of the modules so that I could email them (which we are not allowed to do by the company) to myself (when working from home).
-
- Administrator
- Posts: 78930
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands