+ Reply to Thread
Results 1 to 2 of 2

Import a module file from C:\Drive using a macro?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-25-2004
    Posts
    269

    Import a module file from C:\Drive using a macro?

    I found this code BUT the only thing wrong with it goes to the personal.xls I want it to go to the VBAProdject ThisWorkBook
    The current workbook I opened up.
    Can it search for a wild card like a ? mark or a *

    Example: VBAProdject(Negative Inventory?.xls)
    OR
    VBAProdject(Negative Inventory*.xls)




    Sub CopyModulesFromA()

    Dim FS As Office.FileSearch

    Dim vaFileName As Variant



    Set FS = Application.FileSearch



    With FS

    'clear old search criteria

    .NewSearch

    'directory to search

    .LookIn = "C:"

    'look for .bas (Module) files

    .Filename = "*Inventory.bas"

    'carry out search

    .Execute

    For Each vaFileName In .FoundFiles

    MsgBox "About to import module " & vaFileName

    Workbooks("Negative Inventory as of 09-10-2004.xls").VBProject.VBComponents.Import Filename:=vaFileName

    Next vaFileName

    End With

    End Sub


    I changed it to look like this but it does not work:

    Workbooks("Negative Inventory as of*.xls").VBProject.VBComponents.Import Filename:=vaFileName
    Last edited by vane0326; 02-13-2005 at 12:14 AM.

  2. #2
    Forum Contributor
    Join Date
    09-25-2004
    Posts
    269
    I finally got this code from
    chiello

    This code for is when you save one of your macros in C:| Drive or whatever drive
    it will pick up your code and put it in the current VBA Prodject workbook That is open.
    Then ones I have colored is the ones you need to modified to make it work.
    1) Run Macro with destination Workbook CLOSED
    2) When the Open window appears, you can browse your file system and select the file you want


    Sub CopyModulesFromA()

    Dim wbFileName As Variant
    Dim FS As Office.FileSearch
    Dim vaFileName As Variant

    wbFileName = Application.GetOpenFilename("XLS Files (*.xls), *.xls")
    If wbFileName <> False Then
    Application.ScreenUpdating = False
    Workbooks.Open Filename:=wbFileName
    Set FS = Application.FileSearch
    With FS
    'clear old search criteria
    .NewSearch
    'directory to search
    .LookIn = "C:"
    'look for .bas (Module) files
    .Filename = "Inventory.bas"
    'carry out search
    .Execute
    For Each vaFileName In .FoundFiles
    'MsgBox "About to import module " & vaFileName
    ActiveWorkbook.VBProject.VBComponents.Import Filename:=vaFileName
    Next vaFileName
    End With
    Application.ScreenUpdating = True
    End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1