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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,324
Messages
6,124,249
Members
449,149
Latest member
mwdbActuary

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