Renaming the worksheet with the same file extension more than one time with macros?

nonono

Board Regular
Joined
Jul 25, 2018
Messages
59
I have 4 Sheets where it must not be renamed/touched ...
the name is ... "Menu" / "Original" / "Original (2)" / "UTP"

I have to import multiple ".csv" worksheet and rename accordingly to identify them using the macro below

This is my code to identify the sheets which is imported using the file extension only in the folder ...
Code:
Sub SheetIdentifier()
Dim lastcolumn As Long
lastcolumn = Cells(1, Columns.Count).End(xlToLeft).Column
If lastcolumn = 2 Then ActiveSheet.Name = "Tester Utilization"
If lastcolumn = 20 Then ActiveSheet.Name = "Lot History"
If lastcolumn = 12 Then ActiveSheet.Name = "Lot Operation Report"
End Sub

This is my file extension to import the data into the workbook.

".csv" file extension
Code:
Sub GetNewSheetCSVFile()Path = "C:\Users\momo\Desktop\Chip Fab\"
Filename = Dir(Path & "*.CSV")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
End Sub

".xls" file extension
Code:
Sub GetNewSheetXLSFile()Path = "C:\Users\momo\Desktop\Chip Fab\"
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
End Sub

When I tried to retrieve some work books with the same extension it doesn't helps me rename them accordingly ...


Code:
Sub RunGetReport()
    Call GetNewSheetCSVFile
    Call SheetIdentifier
    Call SheetIdentifier
    Call GetNewSheetXLSFile
    Call SheetIdentifier
    Call UTPRedirect
End Sub


Hope someone can help me resolve my problem
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,223,954
Messages
6,175,601
Members
452,658
Latest member
GStorm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top