I have the below code which combines workbooks into one sheet. The path to the folder containing the workbooks is specified in the code. However, what I want to do is use the folder open dialog box so that it prompts the user to select the folder where the files are. I've tried various ways of doing this but so far have not been able to figure it out. Can anyone assist? I am hoping to accomplish this without dramatically modifying my existing code. Thank you
![]()
Sub Consolidate() ' This macro imports (combines) all TSR workbooks into one sheet. ' This defines various objects Dim fName As String, fPath As String, fPathDone As String, OldDir As String Dim wbkOld As Workbook, wbkNew As Workbook, ws As Worksheet Dim LR As Long, NR As Long ' This speeds up the macro. Application.ScreenUpdating = False Application.EnableEvents = False Application.DisplayAlerts = False Application.Calculation = xlCalculationManual ' This defines that the current workbook is the detination for all the TSR workbooks to be copied too. Set wbkNew = ThisWorkbook wbkNew.Activate Sheets("Master").Activate ' This defines the range of each TSR workbook to be copied. NR = Range("A8:BP27").End(xlUp).Row + 1 ' This sets the path of the folder where the TSR workbooks to be imported are stored. OldDir = CurDir fPath = "C:\Documents and Settings\christopher.kline\Desktop\Work Files\Projects\Pending\Automated TSR Process\New TSR Template\TSR Combine Tests\Test A (5 Workbooks)" ChDir fPath fName = Dir("*.xl*") ' This imports the first sheet from each TSR workbook in the folder. Do While Len(fName) > 0 Set wbkOld = Workbooks.Open(fName) Sheets(1).Activate ' This imports only rows where column BO is not blank. LR = Range("BO" & Rows.Count).End(xlUp).Row ' This copies only the given range of data from each TSR. Range("A8:BP27").Copy ' This pastesvalues in column A of the destination workbook. wbkNew.Sheets("Master").Range("A" & NR).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False ' This closes the TSR workbooks and moves on to the next TSR workbook and the next empty row in the destination workbook. wbkOld.Close False NR = Range("A" & Rows.Count).End(xlUp).Row + 1 fName = Dir Loop ' This resets the settings we changed to speed up the macro. Application.ScreenUpdating = True Application.EnableEvents = True Application.DisplayAlerts = True Application.Calculation = xlAutomatic ' This restores the original working path. ChDir OldDir End Sub











LinkBack URL
About LinkBacks
Register To Reply

Bookmarks