Creating a Macro to import data from other Excel document

MancmMonkee

New Member
Joined
Nov 21, 2018
Messages
4
Hi there,

I'm trying to create a series of Macros in a document, that will enable us to import data from a sheet on another document, into a sheet onto the active document.

Multiple people will have access to the document, at different locations, so the files the data is being imported from will not be kept on a shared drive - the Macro will need to locate the document by file name, on someone's desktop.

E.g. - We have a document called R122, which needs to be imported into a tab (also called R122) onto the master document (called GH - DAILY PICKUP). All data from the source file is to be imported to the tab in the master document. That source file will not always be saved at the same location.

Is this even possible to do, and if so, does anyone have any advice on how to do it?

We have a similar scenario with other documents, but if I can get a resolution to the above, I should be able to apply to the other documents - only difference there, is one of those documents will not be pasting the whole data over, just specific columns.

Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This will search the desktop and any subfolders for as file:

Just update the file path and book name.

You'll need to add the reference library "Microsoft Scripting Runtime"

Code:
Function Recurse(sPath As String) As String


    Dim FSO As New FileSystemObject
    Dim myFolder As Folder
    Dim mySubFolder As Folder


    Set myFolder = FSO.GetFolder(sPath)
    
        For Each myFile In myFolder.Files
        Debug.Print myFile.Name
            If myFile.Name = "blabla.xlsx" Then                    '''update
                'Workbooks.Open Filename:=myFile
            End If
        Next myFile
    
    For Each mySubFolder In myFolder.SubFolders
        For Each myFile In mySubFolder.Files
        Debug.Print myFile.Name
            If myFile.Name = "blabla.xlsx" Then                    '''update
                'Workbooks.Open Filename:=myFile
            End If
        Next myFile
    Next mySubFolder


End Function


Sub TestR()


    Call Recurse("C:\Users\andrew.marshall\Desktop\")                    '''update


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top