Muhammad Hussaan
New Member
- Joined
- Dec 13, 2017
- Messages
- 49
- Office Version
- 2013
- Platform
- Windows
Hello, I have multiple workbooks in a folder along with main file Name MOM.xlsm to merge data (find code below) I am having some problem with vba code below, it works fine in my computer as path is drive E and folder is "MOM" , i want to make this macro working independent of drive E. So that i can keep in USB storage and make this file workable. Kind suggest what change i should do to make it workable. Below is the codeSub Mergemom()Dim wbk As WorkbookDim sht As WorksheetDim shtt As WorksheetDim sheetfirst As WorksheetDim sheetsecond As WorksheetDim sheetthird As WorksheetDim wbk2 As WorkbookSet wbk2 = ThisWorkbookDim Filename As StringDim Path As StringPath = "E:\MOM" 'CHANGE Folder PATHFilename = Dir(Path & "*.xlsx")'OPEN EXCEL FILESDo While Len(Filename) > 0 'IF NEXT FILE EXISTS THENSet wbk = Workbooks.Open(Path & Filename)wbk.ActivateFor Each shtt In wbk.Worksheetswbk.ActivateVar = shtt.Nameshtt.SelectRange("A2").SelectRange(Selection, Selection.End(xlToRight)).SelectRange(Selection, Selection.End(xlDown)).SelectSelection.CopyWindows("MOM.xlsm").ActivateDim lr As Integer'Var = sht.NameSheets(Var).Selectlr = wbk2.Sheets(Var).Cells(Rows.Count,1).End(xlUp).RowCells(lr + 1, 1).SelectActiveSheet.PasteNextwbk.Close TrueFilename = DirLoopEnd Sub