copy sheet and export to create new folder

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
672
Office Version
  1. 365
Platform
  1. Windows
how do i export and create new folder based on file name into base folder
i know how to export
what do i add to make new folder?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
try
VBA Code:
Sub sbFolder()
    myFolder = "D:\Test"
    
    If Dir(myFolder, vbDirectory) = "" Then
        MkDir myFolder
    End If
End Sub
 
Upvote 0
hi
i am doing something wrong
my base folder is M:\all\Reports\2023

then i want to process my book and save based on value of cell D2 something like 1.2.2023 or 1.22.2023
how would i use make my folder properly
this code fails
 
Upvote 0
hi
this is my code
it is copying outside of the nee new folder
it creates the folder but the worksheet isnt inside
Rich (BB code):
Sub ExportToFolder()
    Dim ReportDate              As String:              ReportDate = Worksheets("Data Stub").Range("ReportDate")
    Dim PeriodRunFolder         As String:              PeriodRunFolder = Replace(ReportDate, "/", ".")
    Dim NewWB                   As Workbook
    Dim FullFilePath            As String
    
    Call MakeMyFolder(ExportFolder & PeriodRunFolder)
    'Array of Worksheets to Export
    Worksheets("Pay Stubs").Copy
    Set NewWB = ActiveWorkbook
    FullFilePath = ExportFolder & PeriodRunFolder & ".xlsx"
    NewWB.SaveAs FullFilePath
    NewWB.Close SaveChanges:=False
    
    End Sub
 
Upvote 0
thanks you i used a bit and added to what i had already
it works
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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