Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Module question

Try code like the following. Change the lines of code marked with <<< to
your own needs.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


Sub CopyModule()

Dim SourceModuleFile As String
Dim FName As String
Dim ModuleNameToExport As String
Dim DestinationFolder As String
Dim SaveDir As String
Dim WB As Workbook

'''''''''''''''''''''''''''''''
' Save the current directort
' setting.
'''''''''''''''''''''''''''''''
SaveDir = CurDir

''''''''''''''''''''''''''''''
' Name of the module to
' export from ThisWorkbook.
''''''''''''''''''''''''''''''
ModuleNameToExport = "Module1" '<<< CHANGE
''''''''''''''''''''''''''''''
' Filename of exported file.
''''''''''''''''''''''''''''''
SourceModuleFile = ThisWorkbook.Path & "\" & ModuleNameToExport & ".bas"
''''''''''''''''''''''''''''''
' Kill the existing file if
' necessary.
''''''''''''''''''''''''''''''
On Error Resume Next
Kill SourceModuleFile
On Error GoTo 0
''''''''''''''''''''''''''''''
' Name of the folder containing
' all of the files into which
' the module will be imported.
''''''''''''''''''''''''''''''
DestinationFolder = "C:\Temp" '<<<<<<< CHANGE
''''''''''''''''''''''''''''''
' Export the module:
''''''''''''''''''''''''''''''
ThisWorkbook.VBProject.VBComponents(ModuleNameToEx port).Export _
FileName:=SourceModuleFile
''''''''''''''''''''''''''''''
' Change directory to
' DestinationFolder
''''''''''''''''''''''''''''''
ChDrive DestinationFolder
ChDir DestinationFolder

''''''''''''''''''''''''''''''
' Loop through files in
' DestinationFolder
''''''''''''''''''''''''''''''
FName = Dir("*.xls")
Do Until FName = vbNullString
If CurDir & ThisWorkbook.Name < ThisWorkbook.FullName Then
Set WB = Workbooks.Open(FileName:=FName)
If WB.VBProject.Protection = 0 Then
On Error Resume Next
Err.Clear
WB.VBProject.VBComponents.Import _
FileName:=SourceModuleFile
If Err.Number Then
Debug.Print "Could not import into " & WB.Name & "." &
vbCrLf & _
"Probably 'Access To VBAProject' is not allowd."
End If
WB.Close savechanges:=True
End If
End If
FName = Dir()
Loop
''''''''''''''''''''''''''''''
' Restore directory
''''''''''''''''''''''''''''''
ChDrive SaveDir
ChDir SaveDir

End Sub


"C_Ascheman" wrote in message
...
Is there a way to copy the module from the master workbook to all other
workbooks in a folder?

C_Ascheman



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Module question NickHK Excel Programming 0 January 16th 07 01:54 AM
Class Module Question Andrew Yates Excel Programming 8 March 5th 06 03:50 PM
Class module question David Excel Programming 4 September 8th 05 04:51 PM
ThisWorkbook module question Stuart[_5_] Excel Programming 3 July 17th 04 02:32 PM


All times are GMT +1. The time now is 10:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"