Advice to create 12 Folders & copuy/paste worksheet within

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Evening,
I wish to make things easier for myself at the end of the tax year by creating 12 folers & to copy / paste a worksheet to each folder.

Some info to assist you.
I will have a command button on a worksheet to run the code.
The folders to be created should be named as below,
04 APRIL, 05 MAY, 06 JUNE, 07 JULY, 08 AUGUST, 09 SEPTEMBER, 10 OCTOBER, 11 NOVEMBER, 12 DECEMBER, 13 JANUARY, 14 FEBRUARY, 15 MARCH, 16 APRIL

The worksheet that should be copied is called ACCOUNTS.xlsm
It will always be located here, DESKTOP,EBAY,ACCOUNTS,TEMPLATES,ACCOUNTS.xlsm

The worksheet should be copied & pasted into each of the created folders.
These folders will also be saved at the same location, DESKTOP,EBAY,ACCOUNTS

Thanks very much
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Currently trying to get it to work with 1 folder.
Code in use supplied below.

With this code i see the new folder created 04 APRIL but then get a run time error 70 PERMISSION DENIED
When i debug it the line shown in RED below is highlighted

Rich (BB code):
Private Sub CommandButton1_Click()

Dim folderPath As String
Dim cfolder As String
Dim pfolder As String
folderPath = "C:\Users\Ian\Desktop\EBAY\ACCOUNTS\04 APRIL"

If Dir(folderPath, vbDirectory) = "" Then

    
MkDir folderPath

End If
cfolder = "C:\Users\Ian\Desktop\EBAY\ACCOUNTS\"
pfolder = "C:\Users\Ian\Desktop\EBAY\ACCOUNTS\04 APRIL\"
FileCopy cfolder & "NEW TAX YEAR.xlsm", pfolder & "04 APRIL_NEW TAX YEAR.xlsm"
End Sub
 
Upvote 0
The code below now works.
Just need some pointers as to how i create the 12 different folders thanks

Rich (BB code):
Private Sub CommandButton1_Click()

Dim folderPath As String
Dim cfolder As String
Dim pfolder As String
folderPath = "C:\Users\Ian\Desktop\EBAY\ACCOUNTS\04 APRIL"

If Dir(folderPath, vbDirectory) = "" Then

    
MkDir folderPath

End If
cfolder = "C:\Users\Ian\Desktop\EBAY\ACCOUNTS\TEMPLATES\"
pfolder = "C:\Users\Ian\Desktop\EBAY\ACCOUNTS\04 APRIL\"
FileCopy cfolder & "ACCOUNTS.xlsm", pfolder & "ACCOUNTS.xlsm"

MsgBox "FOLDER & WORKSHEETS NOW CREATED"

End Sub
 
Upvote 0
Hi,
I Have a command button which calls this Macro to create the Folders of which it does well.

Before i run this code can you advise please who i can check first if the folders exist & if so advise the user but if not then continue & create them

Rich (BB code):
Sub MakeFolders()

Dim Rng As Range

Dim maxRows, maxCols, r, C As Integer

Set Rng = Selection

maxRows = Rng.Rows.Count

maxCols = Rng.Columns.Count

For C = 1 To maxCols

r = 1

Do While r <= maxRows

If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, C), vbDirectory)) = 0 Then

MkDir (ActiveWorkbook.Path & "\" & Rng(r, C))

On Error Resume Next

End If

r = r + 1

Loop

Next C

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,680
Members
449,091
Latest member
peppernaut

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