+ Reply to Thread
Results 1 to 5 of 5

Macro to create tab/file and email

  1. #1
    Registered User
    Join Date
    12-01-2008
    Location
    India
    MS-Off Ver
    Microsoft 365 Enterprise - Excel version2301
    Posts
    67

    Macro to create tab/file and email

    Hi

    I need help on a Macro.

    I have an Excel file wherein I have three tabs "List", "Template", "PO Report". Template is linked to PO Report and in the List I have number of Cost Centers in Column A. What i need is to create a copy of Template as per the list ( which will be fluctuating) in the LIST tab. Rename the tabs created as per List ( Cost Centers).-----(1)

    Secondly i want to create separate file for each of the tab created with tab name.----(2)

    Thirdly a Macro to email each work sheet created at (1) or file created at (2) as per the list to separate Cost Center owners.


    For First i am using the below code, the problem with this is everyday list of cost center increases/decreases i have change the number of cost centers in the code for which tabs to be created . It should automaticaly pick the Cost Center from the list until blank cell is found.
    Option Explicit

    Sub Copy_Sheets()

    Dim i As Integer
    Dim wks As Worksheet

    Set wks = Sheets("List")

    For i = 1 To 6
    Sheets("Template").Copy After:=Sheets(2)
    ActiveSheet.Name = wks.Cells(i, 1)
    ActiveSheet.Cells(1, 2) = wks.Cells(i, 1)
    Next

    End Sub


    For (2) I am using the below code, the problem with this is it creates a file of all the tabs in the file i.e. It creates a separate file for "LIST", "Template" and "PO Report" as well. It should only create file of cost centers as per the List only.

    Sub SaveEachWS()
    Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets
    ws.Copy
    ActiveWorkbook.SaveAs Filename:=ws.Name
    ActiveWorkbook.Close
    Next ws

    End Sub

    For (3)

    I could not create code, It should email the tabs / files created from the email address in a partcular cell it may be A1 or D2 anything.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to create tab/file and email

    Hi, Amarjeet Singh,

    mabe you could wrap up your procedures with code-tags as requested by Forum Rule #3?

    From what I understand you could combine the first two procedures into something like this
    Please Login or Register  to view this content.
    As you have been very quiet about the mail program to use and which cell to hold the address maybe you have a look at Mail every worksheet with address in A1 which might be integrated into the code of the procedure as well.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to create tab/file and email

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    12-01-2008
    Location
    India
    MS-Off Ver
    Microsoft 365 Enterprise - Excel version2301
    Posts
    67

    Re: Macro to create tab/file and email

    Hi Holger,

    Thanks for your help, It's giving error at [ ActiveSheet.Move
    ActiveWorkbook.SaveAs ActiveSheet.Name
    ActiveWorkbook.Close]
    Saying File name already exist in the location?

    Thanks

  5. #5
    Registered User
    Join Date
    12-01-2008
    Location
    India
    MS-Off Ver
    Microsoft 365 Enterprise - Excel version2301
    Posts
    67

    Re: Macro to create tab/file and email

    Fixed it . Many thanks for all you help.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to create tab/file and email

    Amarjeet,

    Please check post 3.

+ 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] Trying to create a .pdf and attach it to email, but get .xls file instead
    By sbrnard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2013, 01:21 PM
  2. Replies: 0
    Last Post: 02-21-2013, 04:46 AM
  3. [SOLVED] Create folder, save as pdf, and email file
    By af_lel in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 02-05-2013, 07:35 AM
  4. Replies: 3
    Last Post: 09-30-2011, 04:35 AM
  5. Create a button to Email file using LotusNotes
    By asabti in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-14-2008, 11:39 AM

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