If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Copy macros

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-05, 20:05
bhavesh78 bhavesh78 is offline
Registered User
 
Join Date: Dec 2004
Posts: 78
Question Copy macros

Hi,

I have a template that holds some standard macros required in all worksheets that our company uses. Is there a way to replicate/copy these macros automatically to a new file when a new file is created.

Thanks.

~BS
Reply With Quote
  #2 (permalink)  
Old 02-11-05, 11:31
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
what you could do is export your module to a standard location, then just import on creation of a new workbook,

that would probably work well enough, if you want to do this programatically then you would have to program the VBE,
post back if you would like a hand with any of the above
Dave
Reply With Quote
  #3 (permalink)  
Old 02-14-05, 13:48
bhavesh78 bhavesh78 is offline
Registered User
 
Join Date: Dec 2004
Posts: 78
Is there a way to export the whole project as I have multiple modules ans sheets.

Thanks

~BS
Reply With Quote
  #4 (permalink)  
Old 02-15-05, 07:36
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Ok then id suggest putting a folder template together and adding this module to your workbook and running this will pick up all modules from a folder

Code:
Sub addModules()
'uses microsoft visual basic for applications extensibility 5.3
Dim i As Integer
Dim mypath As String

    'get location of files
    mypath = Application.GetOpenFilename
    mypath = Mid$(mypath, 1, InStrRev(mypath, "\"))
    
    'set up an array of your code modules
    With Application.FileSearch
        .NewSearch
        .FileType = msoFileTypeAllFiles
        .LookIn = Application.GetOpenFilename
        .SearchSubFolders = True '(or false)
        If .Execute > 0 Then
            For i = 1 To .FoundFiles.Count
                'import all modules found
                Application.VBE.ActiveVBProject.VBComponents.Import (.FoundFiles(i))
            Next i
        End If
    End With
    
End Sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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