+ Reply to Thread
Results 1 to 6 of 6

Macro - Generating multiple sheets using a template and source workbook

  1. #1
    Registered User
    Join Date
    03-20-2014
    Location
    Deep in the Alps
    MS-Off Ver
    Excel Mac 2011
    Posts
    4

    Macro - Generating multiple sheets using a template and source workbook

    Hi,

    I am new to the VBA editing and I am missing some steps to get my files correctly generated and then ideally saved in PDF format in the same folder.

    I have two files; one is an invoice template with the following fields:

    Invoice Reference: Line 8 column D
    Issue date: Line 9 column D
    Client name: Line 11 column E&F
    Client address: Line 12 column E&F
    Product name: Line 16 column E&F
    Product details: Line 18 column E&F
    Production date: Line 20 column E&F
    Delivery date: Line 22 column E&F
    Units: Line 24 column E&F
    Total Units: Line 26 column E&F
    Total Invoiced: Line 30 column F

    Each sheet in the "template" workbook should be named after the Invoice Reference.

    Secondly I have the source file in which the data is organized as follows: (Both are in the same folder)

    Invoice Reference: column A
    Issue date: column B
    Client name: column C
    Client address: column D
    Product name: F
    Product details: column G
    Production date: column H
    Delivery date: column I
    Units: column J
    Total Units: column J
    Total Invoiced: column E

    One invoice needs to be created per line in the source workbook.

    I would be very thankful if anyone could help me out with this as I tried many times the macro recording without getting the correct outputs.

    Best regards,

    Benjamin

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Macro - Generating multiple sheets using a template and source workbook

    The general idea would be something like

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    03-20-2014
    Location
    Deep in the Alps
    MS-Off Ver
    Excel Mac 2011
    Posts
    4

    Re: Macro - Generating multiple sheets using a template and source workbook

    Thank you very much for your answer.
    The source file name is "grand-livre.xlsx" and the template file name is "invoice-template.xls"
    In which file do I store this macro? Do they both need to be saved in ".xlsm" format?

  4. #4
    Registered User
    Join Date
    03-20-2014
    Location
    Deep in the Alps
    MS-Off Ver
    Excel Mac 2011
    Posts
    4

    Re: Macro - Generating multiple sheets using a template and source workbook

    also, where do you declare the source workbook and worksheet?

  5. #5
    Registered User
    Join Date
    03-20-2014
    Location
    Deep in the Alps
    MS-Off Ver
    Excel Mac 2011
    Posts
    4

    Re: Macro - Generating multiple sheets using a template and source workbook

    OK got it to work.
    The macro is saved in the source file.
    Here is the full code, it works perfectly Thank you again!

    Sub InvoiceGenerator()

    Dim lngR As Long
    Dim wB As Workbook
    Dim wS As Worksheet

    Set wS = ActiveSheet

    For lngR = 2 To wS.Cells(wS.Rows.Count, 1).End(xlUp).Row
    Set wB = Workbooks.Open("invoice-template.xltm")
    With wB.Worksheets(1)
    .Range("D8").Value = wS.Cells(lngR, "A").Value
    .Range("D9").Value = wS.Cells(lngR, "B").Value
    .Range("E11").Value = wS.Cells(lngR, "C").Value
    .Range("E12").Value = wS.Cells(lngR, "D").Value
    .Range("E16").Value = wS.Cells(lngR, "F").Value
    .Range("E18").Value = wS.Cells(lngR, "G").Value
    .Range("E20").Value = wS.Cells(lngR, "H").Value
    .Range("E22").Value = wS.Cells(lngR, "I").Value
    .Range("E24").Value = wS.Cells(lngR, "J").Value
    .Range("E26").Value = wS.Cells(lngR, "J").Value
    .Range("F30").Value = wS.Cells(lngR, "E").Value

    End With
    wB.SaveAs wS.Cells(lngR, "A").Value & ".xlsm"
    wB.Worksheets(1).ExportAsFixedFormat Type:=xlTypePDF, Filename:=wS.Cells(lngR, "A").Value & ".pdf"
    wB.Close False
    Next lngR

    End Sub

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Macro - Generating multiple sheets using a template and source workbook

    Quote Originally Posted by 4ng3l1s4 View Post
    OK got it to work....it works perfectly Thank you again!
    Congrats on working it out for yourself - a learning moment!

+ 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] Macro to copy cells from multiple sheets in workbook to multiple sheets in other workbook
    By KeithMale in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2013, 05:37 PM
  2. Creating a macro to reformat multiple sheets into a new template
    By Etachias in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2013, 12:38 AM
  3. Create multiple sheets in new workbook based on credentials in source workbook
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-07-2011, 10:31 AM
  4. [SOLVED] Generating Footers for Multiple sheets in Workbook
    By Ron in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2006, 12:35 PM
  5. Generating multiple sheets within a workbook all titled with a ca.
    By Matt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2005, 06:06 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