+ Reply to Thread
Results 1 to 2 of 2

Problem to create different folders with a macro

  1. #1
    Forum Contributor
    Join Date
    04-03-2021
    Location
    Zaragoza
    MS-Off Ver
    2102 MICROSOFT 365
    Posts
    153

    Problem to create different folders with a macro

    Hello everybody,

    I have a question about one of my macros

    I have the main tab “data” and then I have several tabs with the name of the cities of the data tab

    I have done a macro to delete some of the columns this part actually work
    Sub SplitLocation()
    On Error Resume Next
    Application.ScreenUpdating = False
    Dim Ciudad As Worksheet, NombreCarpeta As String, Ruta As String
    '
    With Sheets("Data")
    Mensaje = MsgBox("¿Está seguro de que quiere borrar el contenido de la actuales filas 1 y 2?", _
    vbYesNo, "BORRAR CONTENIDO FILAS 1 Y 2")
    Select Case Mensaje
    Case vbYes
    .Rows("1:2").ClearContents
    Case vbNo
    End Select
    '
    Mensaje = MsgBox("¿Está seguro de que quiere borrar las actuales columnas B y E?", _
    vbYesNo, "BORRAR LAS ACTUALES COLUMNAS B y E")
    Select Case Mensaje
    Case vbYes
    .Range("B:B, E:E").EntireColumn.Delete
    Case vbNo
    GoTo Siguiente
    End Select
    End With


    but the following part does not work


    Siguiente:
    Exit Sub
    NombreCarpeta = "Macro"
    MkDir ThisWorkbook.Path & "\" & C:\Users\PedroHernandez\OneDrive - Macrixx\Desktop\Macro '
    Ruta = ThisWorkbook.Path & "\" & C:\Users\PedroHernandez\OneDrive - Macrixx\Desktop\Macro & "\"
    For Each Ciudad In Sheets
    If Not Ciudad.Name = "Data" And Not Ciudad.Name = "Pivot" Then
    Kill Ruta & Ciudad.Name & ".xlsx"
    Ciudad.Copy
    ActiveWorkbook.SaveAs Ruta & Ciudad.Name & ".xlsx"
    ActiveWorkbook.Close SaveChanges:=True
    End If
    Next
    MsgBox ("Los nuevos Libros con el nombre de las Hojas (Ciudades), se han guardado en " & Ruta)
    End Sub

    What I want the Macro to do is that it creates a folder per each city (each tab) from the “Macro for different workbooks template which is located in the following folder (the file is located in the folder “Macro”)

    C:\Users\PedroHernandez\OneDrive - Macrixx\Desktop\Macro

    Can you please help?

    Thank you
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,673

    Re: Problem to create different folders with a macro

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. 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, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then 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

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. Macro to create folders and subfolders
    By Sun13Banjo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2019, 07:26 AM
  2. Macro to Create Folders and Sub-Folders from columns and add Hyperlinks
    By kripat-96 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2017, 05:06 AM
  3. Create folders and sub folders from lists of data in excel
    By matthruba in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2016, 11:28 AM
  4. [SOLVED] Code to create Folders and sub folders based on variable cell values
    By maxwell13 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-03-2015, 09:28 PM
  5. Create folders and save text files to these folders
    By bloomingcarrot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2014, 08:14 PM
  6. [SOLVED] Create folders and Sub folders and Sub-Sub folders from 5 columns with VBA
    By arleutwyler in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-11-2014, 04:16 PM
  7. Create folders and move and copy files into that folders
    By vijaybharthi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2010, 04:01 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