VBA save File with Cell Value in specific Folder

Luke16398

New Member
Joined
Feb 11, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

My Idea is, that wenn i run the code, a Sheet is saved in a folder like the cell Value (B5). And if the Folder doesn't exist it will be created with the Cell Value (B5)

My code so far:

Dim Path As String
Dim filename As String
Dim wb As Workbook

Set wb = Workbooks.Add
ThisWorkbook.Sheets("Sheet2").Copy Before:=wb.Sheets(1)
Path = "C:\Users\Desktop\test\"
filename = Worksheets("Sheet2").Range("B5").Value & "_" & Worksheets("Sheet2").Range("E5").Value & ".xls"
wb.SaveAs filename:=Path & filename & ".xls"

so i can save the File with the Values of Cell (B5) and (E5) in the Folder "test"
But i want it to save the File, if for example the Cell Value (B5) is "ABCD", in the Path: C:\Users\Desktop\test\ABCD\
and if the Cell Value is "EFGH" in the Path C:\Users\Desktop\test\EFGH\ an so on.

Can someone please help me?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Not following.
You want the file to be saved in both ABCD and EFGH folders? Then do separate saves.
Or whichever of B5 and E5 is not blank? Then test for either cell having no value.
You're also saying the folder might not exist? Then Dir function will return "" if you test the path and it does not exist.

Users can choose a folder for file storage using msoFileDialogFolderPicker. You might want to check that out.
 
Upvote 0
I want to save the sheet in the folder wich has the value of B5
If the cell hast the value ABCD the file should be saved in the folder ABCD if the Cell has another value the file should be saved in the folder whichever is the same name of that cell
So whenever i change the cell value the Code should search for that value and save the file in the folder witch has the same name of that cell
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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