I'm getting stuck atm with an excel vba macro.
I like to do the following.
A File is lying on a Network Drive. Ie.
H:\Excel Files\LocationA\
In this folder are many Excel Files all are the same with diffrent data.
I need to read out 2 Cell Values and put them in a new Excel File.
I need the Cel value not the formula or format.
So the Excel Files are Closed
My Script below is working but. It crashes during the process i think in case of opening and close the excel Files. Maybe there are some latency Problems on the Network drive.
Further there are 2 other Locations
H:\Excel Files\LocationB\
H:\Excel Files\LocationC\
If i have finaly working the LocationA I like to copy the loop for the other 2 Location. So maybe i need more Variables.
Sub LoopAllExcelFilesInFolder()
Dim wb As Workbook
Dim myPathLiestal As String
Dim myPathMuttenz As String
Dim myPathReinach As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
'Optimize Macro Speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
myPathLocationA = "H:\Excel\LocationA\"
'Message Box when tasks are completed
MsgBox "Die Daten werden verarbeitet. Bitte haben sie einen Moment geduld"
'Target File Extension (must include wildcard "*")
myExtension = "*.xls*"
'Target Path with Ending Extention
myFile = Dir(myPathLocationA & myExtension)
'Set Dest Path with Ending Extention
Set wsDest = Workbooks("Test.xlsm").Worksheets("2019")
'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(Filename:=myPathLocationA & myFile)
DestLastRowA = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row
'DestLastRowB = wsDest.Cells(wsDest.Rows.Count, "B").End(xlUp).Offset(1).Row
'Mitarbeiter Namen werden aus der Zelle Q1 kopiert
wb.Worksheets("2019").Range("Q1").Copy
wsDest.Range("A" & DestLastRowA).PasteSpecial xlPasteValues
'Mitarbeiter Stundenkontigent werden aus der Zelle W8 kopiert
wb.Worksheets("2019").Range("W8").Copy
wsDest.Range("B" & DestLastRowA).PasteSpecial xlPasteValues
'Save and Close Workbook
wb.Close SaveChanges:=True
Application.CutCopyMode = False 'Clear Clipboard
'Get next file name
myFile = Dir
Loop
'Message Box when tasks are completed
MsgBox "Task Complete!"
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub