Dupe and save a wbk within a new folder, according cells value

Flavien

Board Regular
Joined
Jan 8, 2023
Messages
76
Office Version
  1. 365
Platform
  1. Windows
Hello!

The below vba code works well. With it I can open a template workbook and save it with a new name according cells value.
I'd like to go further and copy/paste a template folder before to save as the new workbook.
Moreover I'd like to make the program more flexible with address of destfolder and workbooks in cells.

Could someone help me please?




Sub Create_Workbooks_v2()
Dim wbToDupe As Workbook
Dim wsExtr As Worksheet
Dim rVar As Range
Dim NewName As String
Dim i As Long

Const DestFolder As String = "F:\Testing\abcd\" '<- Edit as required

Set wbToDupe = Workbooks("To Duplicate.xlsx") '<- Edit as required
Set wsExtr = ThisWorkbook.Sheets("EXTRACTION")
Set rVar = wbToDupe.Sheets("CARTOUCHE").ListObjects(1).DataBodyRange.Cells(1, 2)
With wsExtr
For i = 2 To .Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & i).Resize(, 6).Copy
rVar.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
NewName = rVar.Cells(1, 0).Value & " " & rVar.Cells(1, 1).Value & " GCU - V00.xlsx"
wbToDupe.SaveAs Filename:=DestFolder & NewName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Set wbToDupe = Workbooks(NewName)
Set rVar = wbToDupe.Sheets("CARTOUCHE").ListObjects(1).DataBodyRange.Cells(1, 2)
Next i
wbToDupe.Close
End With
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Your need is not totally clear. Do you want to create a folder for the new workbooks based on a cell value?

Is it possible to see the workbook, maybe with fake but realistic data? You can put a link to the file -- saved to Dropbox, 1 drive, etc. -- using the link icon above the message box.

Another option is to provide the data using Mr Excel's excellent addin called XL2BB. See HERE.

If you want the folder to be specified in a cell helper will need to know which cell contains it.
 
Upvote 0

Forum statistics

Threads
1,223,333
Messages
6,171,511
Members
452,407
Latest member
Broken Calculator

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