Good afternoon to everyone.
**Attending the Skip's suggestion I move this thread to this forum**
Again I need your help, I try to do myself but I can't.
I need to copy certain sheet into a new excel workbook from multiple workbooks, I have near to hundred "production reports" in one folder in a shared drive inside the production reports I have several sheets and until now I was able to do this task with the sheets named "ElectReport" and with the sheets named "Time_Out" everything fine. Now I need to retrieve another sheet BUT this tab/sheet varies in how is named, this sheet SHOULD be "named" as the employee number (8 digits ie. 20153280), the task for my code works fine because all the tabs for ElectReport has "ElectReport" and when is copied/pasted in the new workbook simply puts "ElectReport" for the first tab copied "ElectReport1" for the second, "ElectReport2" for the third and so on, the same for the "Time_Out" tabs. But due a different employee numbers my macro does not work, here is the code:
Any help with this will be really appreciated.
Thanks in advance and best regards.
Answering the first Skip's question I know the sheet name is the employee number because I design the book to accept his/her employee number taking the number from the system (windows) login info, each user/employee has his/her own login and it is PROHIBITED to use other user name.
For the second question, YES the workbook have 9 (nine) sheets in, no one change the name everyone remains with the same name all the time the only one who change the name is the Employee number sheet the names for ALL sheets are: AllInfo, ToDetAction, ToDetQueue, ExtractedInfo, ToCons, ElectReport, Time_Out, LastConct and the sheet with changing name/numbers.
Again thanks in advance.
**Attending the Skip's suggestion I move this thread to this forum**
Again I need your help, I try to do myself but I can't.
I need to copy certain sheet into a new excel workbook from multiple workbooks, I have near to hundred "production reports" in one folder in a shared drive inside the production reports I have several sheets and until now I was able to do this task with the sheets named "ElectReport" and with the sheets named "Time_Out" everything fine. Now I need to retrieve another sheet BUT this tab/sheet varies in how is named, this sheet SHOULD be "named" as the employee number (8 digits ie. 20153280), the task for my code works fine because all the tabs for ElectReport has "ElectReport" and when is copied/pasted in the new workbook simply puts "ElectReport" for the first tab copied "ElectReport1" for the second, "ElectReport2" for the third and so on, the same for the "Time_Out" tabs. But due a different employee numbers my macro does not work, here is the code:
Code:
Dim objExcel As Excel.Application
Set objExcel = CreateObject("excel.application")
objExcel.Workbooks.Add
objExcel.Visible = True
'''******
'''******
'
'
Application.ScreenUpdating = True
Application.Visible = True
Application.EnableEvents = False
Dim X As Variant
X = Application.GetOpenFilename _
("All File extensions (*.xl*), *.xl*", 2, "Open Files", , True)
If IsArray(X) Then
Workbooks.Add
A = ActiveWorkbook.Name
For y = LBound(X) To UBound(X)
Application.StatusBar = "Importing Files: " & X(y)
Workbooks.Open X(y)
b = ActiveWorkbook.Name
For Each Hoja In ActiveWorkbook.Sheets(Array("ElectReport")) 'here is the problem I think
Hoja.Copy After:=Workbooks(A).Sheets(Workbooks(A).Sheets.Count)
Next
Workbooks(b).Close False
Next
Application.StatusBar = "Ready"
End If
Range("a1").Select
Call UnhideAllSheets
Call UnprotectAll
Call DelEmptySheets
MsgBox ("yes no")
Call RenameSheets
Call Sort_Active_Book
ActiveWorkbook.Worksheets(1).Activate
Application.Goto Reference:="R1C1"
Application.ScreenUpdating = False
End Sub
Any help with this will be really appreciated.
Thanks in advance and best regards.
SkipVought said:Hi,
This question would be best addressed in forum707: VBA Visual Basic for Applications (Microsoft). This forum is not designed for VBA questions. Please repost and then delete this thread.
Please tell us how you will know that a sheet name is an employee number. Are there other sheets in these workbooks that have known names where the logic might be any sheet other than this list of known sheet names?
Answering the first Skip's question I know the sheet name is the employee number because I design the book to accept his/her employee number taking the number from the system (windows) login info, each user/employee has his/her own login and it is PROHIBITED to use other user name.
For the second question, YES the workbook have 9 (nine) sheets in, no one change the name everyone remains with the same name all the time the only one who change the name is the Employee number sheet the names for ALL sheets are: AllInfo, ToDetAction, ToDetQueue, ExtractedInfo, ToCons, ElectReport, Time_Out, LastConct and the sheet with changing name/numbers.
Again thanks in advance.