Hi - hoping someone better than me can help with a slight adjustment to the below code. I think its easy for someone with the skills.
So it currently opens all the files in a picked folder and renames the sheet to Sheet1, so long as there's only one sheet.
Problem is I have a combination of XLSX files and XLS files. Yes, xls files, its embarassing I know.
I'm not sure if the code will open the xls files. Can it be altered to do so if it doesnt already?
Even better, could the code be changed to, after opening the xls file and renaming the sheet, then saving the file as XLSX?
and finally, the code is more complex than I need it to be. I dont need it to open a file picker it can just run on the following folder:
\\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\DCA\Invoices\Input
sorry, I know i've asked a lot, but my VBA skills are.......well they're not really skills. Skills is too grand a term.
I'm actually using an Event in Alteryx to run vb code to open an excel and run this VBA code, then close the excel, then run my workflow! So at least I can do somethings.
Any help would be greatly appreciated.
Code:
Sub Rename()
Dim CurrentBook As Workbook
Dim ImportFiles As FileDialog
Dim FileCount As Long
Dim wbName As String
'Open File Picker
Set ImportFiles = Application.FileDialog(msoFileDialogOpen)
With ImportFiles
.AllowMultiSelect = True
.Title = "Pick Files to Adjust"
.ButtonName = ""
.Filters.Clear
.Filters.Add ".xlsx files", "*.xlsx"
.Show
End With
Application.DisplayAlerts = False
Application.DisplayAlerts = False
'Cycle through books
For FileCount = 1 To ImportFiles.SelectedItems.Count
Set CurrentBook = Workbooks.Open(ImportFiles.SelectedItems(FileCount))
wbName = Replace(CurrentBook.Name, ".xlsx", "")
CurrentBook.Activate
ActiveSheet.Name = "Sheet1"
CurrentBook.Close True
Next FileCount
Application.DisplayAlerts = True
Application.DisplayAlerts = True
End Sub
So it currently opens all the files in a picked folder and renames the sheet to Sheet1, so long as there's only one sheet.
Problem is I have a combination of XLSX files and XLS files. Yes, xls files, its embarassing I know.
I'm not sure if the code will open the xls files. Can it be altered to do so if it doesnt already?
Even better, could the code be changed to, after opening the xls file and renaming the sheet, then saving the file as XLSX?
and finally, the code is more complex than I need it to be. I dont need it to open a file picker it can just run on the following folder:
\\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\DCA\Invoices\Input
sorry, I know i've asked a lot, but my VBA skills are.......well they're not really skills. Skills is too grand a term.
I'm actually using an Event in Alteryx to run vb code to open an excel and run this VBA code, then close the excel, then run my workflow! So at least I can do somethings.
Any help would be greatly appreciated.
Code:
Sub Rename()
Dim CurrentBook As Workbook
Dim ImportFiles As FileDialog
Dim FileCount As Long
Dim wbName As String
'Open File Picker
Set ImportFiles = Application.FileDialog(msoFileDialogOpen)
With ImportFiles
.AllowMultiSelect = True
.Title = "Pick Files to Adjust"
.ButtonName = ""
.Filters.Clear
.Filters.Add ".xlsx files", "*.xlsx"
.Show
End With
Application.DisplayAlerts = False
Application.DisplayAlerts = False
'Cycle through books
For FileCount = 1 To ImportFiles.SelectedItems.Count
Set CurrentBook = Workbooks.Open(ImportFiles.SelectedItems(FileCount))
wbName = Replace(CurrentBook.Name, ".xlsx", "")
CurrentBook.Activate
ActiveSheet.Name = "Sheet1"
CurrentBook.Close True
Next FileCount
Application.DisplayAlerts = True
Application.DisplayAlerts = True
End Sub