+ Reply to Thread
Results 1 to 11 of 11

VBA for Template and Copying Cells.

  1. #1
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    383

    VBA for Template and Copying Cells.

    Hi all. I have the following macro which when executed, this is what it does :

    Step 1: It Opens 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 document
    Step 3: A new workbook (based on a saved template) is created with the name inputted in step 2 above.

    The code is the following and can be viewed below. (Merits to Norie who suggested to use the Add.method for this code).

    Please Login or Register  to view this content.

    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 the macro should function:
    Step 1: It Opens 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 document
    Step 3: A new workbook (based on the saved template) is created with the name inputted in step 2 above. E.g: "Workbook 2"
    Step 4: Some cells from another Workbook, say "Workbook 1" are copied and pasted into the newly created "Workbook 2".
    Step 5: Save and close Workbook 2

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

    Thanks everyone

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA for Template and Copying Cells.

    You can use something like this with some tweaks-

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Here the MainWbk is work newly created workbook where the data is to be copied.
    TempWbk is the workbook from where the data is to be copied
    Workbooks.Open "C:\Users\Desktop\Upload.xlsx" - Path of your TempWbk
    And change the ranges as required..
    Last edited by NeedForExcel; 06-12-2015 at 12:52 AM.
    Cheers!
    Deep Dave

  3. #3
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    383

    Re: VBA for Template and Copying Cells.

    Hey,

    Thanks a lot for your help. That worked out very great !!!


    If it is not too much of a bother to ask, is it possible to also do the following with the codes outlined above:

    Step 1: A macro is run from "WorkBook1".It Opens 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 document
    Step 3: A new workbook (based on the saved template) is created with the name inputted in step 2 above. E.g: "Workbook 2"
    Step 4: Some cells from "Workbook 1" (the same workbook mentioned in Step 1) are copied and pasted into the newly created "Workbook 2".
    Step 5: Save and close Workbook 2

    I don't know if this can be done! Appreciate a lot your kind help

    Big Thanks

  4. #4
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    383

    Re: VBA for Template and Copying Cells.

    Hey,

    Thanks a lot for your help. That worked out very great !!!


    If it is not too much of a bother to ask, is it possible to also do the following with the codes outlined above:

    Step 1: A macro is run from "WorkBook1".It Opens 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 document
    Step 3: A new workbook (based on the saved template) is created with the name inputted in step 2 above. E.g: "Workbook 2"
    Step 4: Some cells from "Workbook 1" (the same workbook mentioned in Step 1) are copied and pasted into the newly created "Workbook 2".
    Step 5: Save and close Workbook 2

    I don't know if this can be done! Appreciate a lot your kind help

    Big Thanks

  5. #5
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA for Template and Copying Cells.

    Hi,

    But this is what the 2 codes above are doing right?

    Not sure, what extra is required..

    Can you please clarify?

  6. #6
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    383

    Re: VBA for Template and Copying Cells.

    Ah ok I guess I am doing it wrong. Sorry for the inconvenience, if I may ask for some additional help.

    The first code works great. I run the macro from "Workbook 1", the "template" opens, a new windows opens prompting the user to insert the name of a new document.
    The document is created

    However I got stuck when the second code is run (maybe I am inserting the wrong paths?). The cells are not copying to the newly created worksheet. I tried to change the path but it will say that the 'Worksheet is already open.."

    Thanks a lot!

  7. #7
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA for Template and Copying Cells.

    The Cells might not be copying because I have generically used Range("A1").CurrentRegion.

    You will need to change it as per your actual sheet..

    If you need help with that, please attach your template and the 2nd workbook.. I'll help you out..

    Cheers!

  8. #8
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    383

    Re: VBA for Template and Copying Cells.

    That would be great. Really thanks a lot!

    I have attached a small extract from the data I am using, so as to make it more straightforward.

    I am working with 'WorkBook1'. This is from where I will run both macros.
    Once macro 1 is run, the document 'Template' opens. A prompt-box tells the user to input the name of a new document and a copy of 'Template' is created. For the sake of argument I will call the new document: "WorkBook2".
    I would like that cells, A30:A34 from "WorkBook1" are copied to "WorkBook2" which has just been created.

    Currently I am having some issues in the last bit, where the cells need to be copied, since I think I have not adjusted the path in the correct way.


    Thanks and really appreciate it, sorry for any inconvenience.
    Attached Files Attached Files

  9. #9
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA for Template and Copying Cells.

    Hi,

    Please see the file attached.

    Change the strTempPath & any other ranges as required.


    Cheers!

    Deep
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    383

    Re: VBA for Template and Copying Cells.

    Terrific That's awesome. Thanks a lot for your kind help. It is amazingly good Cheers, appreciate a lot !

  11. #11
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: VBA for Template and Copying Cells.

    Glad it helped..

    Please mark the thread as solved if you have your answer..

    Cheers!

    Deep

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] copying template
    By twyckoff in forum Excel General
    Replies: 2
    Last Post: 11-06-2014, 06:32 PM
  2. Copying Sheet 1 to template
    By mstrlucky74 in forum Excel General
    Replies: 1
    Last Post: 11-18-2012, 11:28 PM
  3. [SOLVED] Name warning when copying template
    By Hammer_757 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2012, 09:48 PM
  4. Error with VBA code Copying cells to a closed workbook, template sheet, documents and
    By Libster78 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-30-2010, 12:31 PM
  5. Replies: 3
    Last Post: 08-13-2009, 03:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1