+ Reply to Thread
Results 1 to 3 of 3

Save in folder by year

  1. #1
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    Save in folder by year

    Hello, I am trying to add into my code to look for a folder in the save location by year. So, for example: if the year changes from 2023 to 2024, the VBA code will automatically save into the 2024 folder. I hope my terrible explanation makes some sense...
    Please Login or Register  to view this content.
    Dim newFolder As String
    newFolder = Range("c56").Value
    Dim arr1 As Variant
    arr1 = Array("certificate (2)", "certificate")
    ' only create folder if it doesn't already exist
    If Len(Dir(path & newFolder, vbDirectory)) = 0 Then MkDir path & newFolder

    ' update path to include the new folder
    path = path & newFolder & Application.PathSeparator

    Dim FileName As String
    FileName = newFolder & ".xlsm"

    ActiveWorkbook.SaveCopyAs path & FileName
    ActiveWorkbook.Sheets(arr1).Select
    ActiveSheet.ExportAsFixedFormat xlTypePDF, Replace$(path & FileName, ".xlsm", ".pdf")

    MsgBox " Certificate Saved Successfully"

    End Sub[/CODE]

    Thanks.
    Last edited by confused monkey; 10-05-2023 at 08:26 AM.

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

    Re: Save in folder by year

    Just start your code by setting the path - and creating the year folder if it does not exist:

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

  3. #3
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    Re: Save in folder by year

    Thanks for the help. I probably didn't explain it too well, but I would like the path to be e.g.
    Please Login or Register  to view this content.
    with 2023 being the upper folder to c56 folder name.
    Last edited by AliGW; 10-09-2023 at 07:58 AM. Reason: Code tags corrected.

+ 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. Save file in year and month folder of date in range
    By Musto85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2022, 02:17 PM
  2. [SOLVED] Save pdf to specifc year/month folder + manage folders based on CDate
    By vendam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2020, 12:29 AM
  3. Replies: 3
    Last Post: 08-09-2017, 05:09 AM
  4. [SOLVED] Create new folder based on current year + save as
    By gliori in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2017, 07:54 AM
  5. [SOLVED] VBA Code to save to a folder within a folder within a folder all based on cell values.
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-24-2016, 04:24 PM
  6. How to save file in respective month folder as per current year vba modification
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2014, 05:26 PM
  7. Replies: 6
    Last Post: 08-11-2006, 03:41 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