Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-08-2016, 08:28 AM
OfficeNewb OfficeNewb is offline Macro to open Multiple files and copy information to a master file Windows 10 Macro to open Multiple files and copy information to a master file Office 2013
Novice
 
Join Date: Nov 2015
Posts: 4
OfficeNewb is on a distinguished road
Default

Hello gbaker -

Below is a quick example of copying data from external text files into a master Excel Workbook.

Code:
 
Sub ImportMonthlySales()

    Dim myTextFile As Workbook
    Dim OpenFiles() As Variant
    
    OpenFiles = GetFiles()
    Application.ScreenUpdating = False
    
    For i = 1 To Application.CountA(OpenFiles)
        Set myTextFile = Workbooks.Open(OpenFiles(i))
        
        myTextFile.Sheets(1).Range("A1").CurrentRegion.Copy
        Workbooks(1).Activate
        Workbooks(1).Worksheets.Add
        ActiveSheet.Paste
        Application.CutCopyMode = False
        myTextFile.Close
    Next i
    
    Application.ScreenUpdating = True
    
End Sub
 
Private Function GetFiles() As Variant
    
GetFiles = Application.GetOpenFilename(Title:="Select File(s) to import", MultiSelect:=True)
 
End Function
Running the ImportMonthlySales() macro will prompt the user to select the file(s) to be imported. Once the file(s) is found the macro will then import the data to a worksheet in the active Excel workbook.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to open Multiple files and copy information to a master file Run a macro on multiple docx. files Peter Carter Word VBA 27 12-15-2022 04:10 PM
Error when trying to open .docx after I run a macro to copy data between tables in two documents reesjordan Word VBA 3 06-18-2015 12:28 AM
Macro to copy cell info to multiple documents Patrick Innes Word VBA 2 02-18-2015 08:38 PM
Macro to open Multiple files and copy information to a master file how to copy some information from one excel file to another excel file tomlam Excel Programming 4 10-01-2013 03:06 PM
Macro to open Multiple files and copy information to a master file looking for macro for multiple files bolk Word 3 05-03-2011 05:46 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft