VBA to copy & rename closed workbook with variable file extenstion

MrManBoy

New Member
Joined
May 28, 2014
Messages
37
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hi

Trying to achieve: The code below checks the if there is a copy of that file with a predetermined extension and if not, then create the copy with the original extension. However, it has come to my attention, that despite the file names are always the same, the extensions are not. Is there a way to modify the below to accomdate this?

Code:
If Len(Dir("E:\Work\Documents\Stuff\Staff List Reports\HR Copy.[COLOR=#ff0000][B]csv[/B][/COLOR]")) = 0 Then
   FileCopy "E:\Work\Documents\Stuff\Staff List Reports\HR Team Member List.[COLOR=#ff0000][B]csv[/B][/COLOR]", "E:\Work\Documents\Stuff\Staff List Reports\HR Copy.[COLOR=#ff0000][B]csv[/B][/COLOR]"
Else
   MsgBox "Hey mate, you already have a saved HR Copy.", , "Heads up!"
End If
If Len(Dir("E:\Work\Documents\Stuff\Staff List Reports\HW Copy.[COLOR=#ff0000][B]xls[/B][/COLOR]")) = 0 Then
   FileCopy "E:\Work\Documents\Stuff\Staff List Reports\Honeywell Cardholder List.[COLOR=#ff0000][B]xls[/B][/COLOR]", "E:\Work\Documents\Stuff\Staff List Reports\HW Copy.[COLOR=#ff0000][B]xls[/B][/COLOR]"
Else
   MsgBox "Hey champ, you already have a saved HW Copy.", , "Heads up!"
End If

Cheers for any help ;)
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,223,214
Messages
6,170,775
Members
452,353
Latest member
strainu

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