Mass trim file names in a folder

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
121
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi All,

I have daily downloads of files in a folder. The file name suffix always changes with an added "(**) some number in those parentheses. See screen show below.
I would typically, manually edit all the downloaded files suffix, to match my subs syntax can recognize the file name. See two subs examples below.

Is there a way to mass Trim the "(4)"? This number would change daily. Alternatively, is there a way to use a wildcard for each download file name like, "1_CLASS_INTL_Daily***"?



Sub CLASS1_INTL()
Dim MyRange As Range
Windows("1_CLASS_INTL_Daily.csv").Activate
With ActiveSheet.UsedRange
Set MyRange = Range(.Cells(2, 1), .Cells(1, 1).Offset(.Rows.Count - 2, .Columns.Count - 1))
MyRange.Select
Selection.Copy
End With

Windows("Calculator for All Class 8.12.2021.xlsm"). _
Activate
Sheets("CLASS 1 - INTL").Select

Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("1_CLASS_INTL_Daily.csv").Close
End Sub


Sub CLASS2_INTL()

Dim MyRange As Range
Windows("2_CLASS_INTL_Daily.csv").Activate

With ActiveSheet.UsedRange
Set MyRange = Range(.Cells(2, 1), .Cells(1, 1).Offset(.Rows.Count - 2, .Columns.Count - 1))
MyRange.Select
Selection.Copy
End With

Windows("Calculator for All Class 8.12.2021.xlsm"). _
Activate
Sheets("CLASS 2 - INTL").Select

Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("2_CLASS_INTL_Daily.csv").Close
End Sub
1628784560586.png
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
S is a variable that refers to the filename (or window name)of the file (or window) you are trying to close. If the value of S refers to a filename (or window) that does not exist, you will get that error.
 
Upvote 0
won't it be easier to just use
VBA Code:
WB.close
S changes several times so it's value needs to be confirmed at the close attemp.
if it still creates troubles just comment out this row for the moment.
Workbooks can be closed later when all is done.
 
Upvote 0
won't it be easier to just use
VBA Code:
WB.close
S changes several times so it's value needs to be confirmed at the close attemp.
if it still creates troubles just comment out this row for the moment.
Workbooks can be closed later when all is done.
@bobsan42

Thanks very much. I'll try this and let you know.
Imran
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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