Reputation: 5
I am currently using this code to open all .xls files in a folder
Sub OpenFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = InputBox("Please enter the folder for files")
MyFile = Dir(MyFolder & "\*.xls")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
****Sheet1.Name = "MyFile"****
MyFile = Dir
Loop
End Sub
I am trying to change the worksheet name to the file name as it loops though
Every worksheet I am opening will be called "Parts List"
I am trying to use the asterisk portion to do this but it does not work.
Upvotes: 0
Views: 34
Reputation:
This will rename the Worksheets("Parts List") in the newly opened workbook to MyFile.
Sub OpenFiles()
Dim wb As Workbook
Dim MyFolder As String
Dim MyFile As String
MyFolder = InputBox("Please enter the folder for files")
MyFile = Dir(MyFolder & "\*.xls")
Do While MyFile <> ""
Set wb = Workbooks.Open(Filename:=MyFolder & "\" & MyFile)
wb.Worksheets("Parts List").Name = MyFile
MyFile = Dir
Loop
End Sub
Upvotes: 1