Hi All,
Like many, I'm new to VBA and have had a tough time with a macro that I've pieced together...I need some help, please .
I have been trying to write a Macro that opens up all workbooks in a particular folder which then copies the first sheet of each of those workbooks to the workbook that is running the macro into separate new sheets.
Where I have got to is that I have the macro, I can run it and it will do pretty much what I want. But....when I go to save the file Excel crashes - every time. Thing is it doesn't crash immediately. I can interact with the workbook, delete sheets, change things etc etc, but when I go to 'save' or 'save as' it will crash.
If anyone has any suggestions, I would really appreciate it. This thing is killing me! The code is below, apologies if it isn't very polished and awkward, but it's all I got.
Just a couple of notes which might help: "Open Workbooks.xlsb" is the workbook that has and runs the macro and is where the sheets are copied to from the other workbooks in the folder. The files (.xlsx) I'm opening and closing are in the "C:\Test\" folder and I'm doing this on a notebook running XP.
Thanks in advance to anyone who might be able to help!
Public Sub OpenWorkbooksThenCopySheetToCurrentWorkBook()
Dim strFile As String
Dim strDirectory As String
strDirectory = "C:\Test\"
strFile = Dir(strDirectory & "*.xlsx*")
Do Until strFile = ""
Workbooks.Open strDirectory & strFile
Workbooks(strFile).Activate
Sheets(strFile).Select
Sheets(strFile).Copy After:=Workbooks("Open WorkBooks.xlsb"). _
Sheets(3)
Workbooks("Open WorkBooks.xlsb").Activate
Workbooks(strFile).Activate
Workbooks(strFile).Close SaveChanges:=False
Workbooks("Open WorkBooks.xlsb").Activate
strFile = Dir()
Loop
End Sub
Like many, I'm new to VBA and have had a tough time with a macro that I've pieced together...I need some help, please .
I have been trying to write a Macro that opens up all workbooks in a particular folder which then copies the first sheet of each of those workbooks to the workbook that is running the macro into separate new sheets.
Where I have got to is that I have the macro, I can run it and it will do pretty much what I want. But....when I go to save the file Excel crashes - every time. Thing is it doesn't crash immediately. I can interact with the workbook, delete sheets, change things etc etc, but when I go to 'save' or 'save as' it will crash.
If anyone has any suggestions, I would really appreciate it. This thing is killing me! The code is below, apologies if it isn't very polished and awkward, but it's all I got.
Just a couple of notes which might help: "Open Workbooks.xlsb" is the workbook that has and runs the macro and is where the sheets are copied to from the other workbooks in the folder. The files (.xlsx) I'm opening and closing are in the "C:\Test\" folder and I'm doing this on a notebook running XP.
Thanks in advance to anyone who might be able to help!
Public Sub OpenWorkbooksThenCopySheetToCurrentWorkBook()
Dim strFile As String
Dim strDirectory As String
strDirectory = "C:\Test\"
strFile = Dir(strDirectory & "*.xlsx*")
Do Until strFile = ""
Workbooks.Open strDirectory & strFile
Workbooks(strFile).Activate
Sheets(strFile).Select
Sheets(strFile).Copy After:=Workbooks("Open WorkBooks.xlsb"). _
Sheets(3)
Workbooks("Open WorkBooks.xlsb").Activate
Workbooks(strFile).Activate
Workbooks(strFile).Close SaveChanges:=False
Workbooks("Open WorkBooks.xlsb").Activate
strFile = Dir()
Loop
End Sub