VBA for Template and Copying Cells.

Keibri

New Member
Joined
May 29, 2015
Messages
8
Hi all. I have the following macro which when executed, this is what it does :

Step 1: A macro is run from "WorkBook 1". Once clicked, the macro would open a saved template, called "Template", from a defined location.
Step 2: An Input Box appears, prompting the user to insert a new name for a new workbook
Step 3: A new workbook, based on "Template", is created with the name inputted in step 2 above. E.g: the new name would be "Workbook 2". In summary, a copy of "Template" is produced and the name used in Step 2 -"Workbook 2"- is given to this new copy.

The code is the following and can be viewed below.


Code:
[/COLOR]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">Sub trial()
Dim wbNew As Workbook
Dim strTempPath As String
Dim strTempName As String
Dim strNewName As String


    strTempPath = "C:\Users\User\Documents\Accounts\W&E\"
    strTempName = "Template.xltm"

    Set wbNew = Workbooks.Add(Template:=strTempPath & strTempName)

    strNewName = InputBox("Please enter workbook's name:")

    
    wbNew.SaveAs strTempPath & strNewName, xlOpenXMLWorkbookMacroEnabled



End Sub</code>[COLOR=#333333]



What I would like to do, if it is possible, is that I would like to copy some cells from another workbook into this newly created workbook.

Therefore, for example, this is how I'd like the macro to work:
Step 1: A macro is run from "WorkBook 1". Once clicked, the macro would open a saved template, called "Template", from a defined location.
Step 2: An Input Box appears, prompting the user to insert a new name for a new workbook
Step 3: A new workbook, based on "Template", is created with the name inputted in step 2 above. E.g: the new name would be "Workbook 2". In summary, a copy of "Template" is produced and the name used in Step 2 -"Workbook 2"- is given to this new copy.
Step 4: Some cells from "WorkBook 1" (identified in Step 1 above), are copied and pasted into the newly created "Workbook 2".
Step 5: Save and close Workbook 2

Up till now, the code caters for Step 1 to Step 3. But I would like to include Step 4 and Step 5. I had posed a similar question in the link below, but I was wondering if I could receive additional guidance:

VBA for Template and Copying Cells.




Can someone help me out if this is possible. Appreciate a lot.


Thanks everyone
smile.gif
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,920
Messages
6,122,262
Members
449,075
Latest member
staticfluids

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