VBA: Check If Both Files (Original and Copy) Are In Same Directory Through SaveAs Dialog Box

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Code:
Sub SaveFileCode
ChDrive ThisWorkbook.Path 
ChDir ThisWorkbook.Path 

FileSaveAs = Application.GetSaveAsFilename(FileFilter:="Exel Files (*.xlsm),*.xlsm",Title:="Add Name")

If FileSaveAs = False Then 
        MsgBox "Operation terminated"
Else
       Application.EnableEvents=False 
       ThisWorkbook.SaveAs FileName:=FileSaveAs, FileFormat:=52, Password:="", writerespassword:="", ReadOnlyRecommended:=False 
       Application.EnableEvents=True
End Sub

When I click on the Save button, I want to verify if the workbook (original) is in the same folder as the copy (new workbook to be saved).

If that can be done, can someone please show me the way and how it's done?

Thanks in advance
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi,​
with some comparison like If Left(FileSaveAs, InStrRev(FileSaveAs, "\") - 1) = ThisWorkbook.Path Then …​
 
Upvote 0
Solution
Okay @Marc L
I will run the test and give you feedback shortly.

I am not with my pc ATM
 
Upvote 0
It worked perfectly. Thanks and have a great time.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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