+ Reply to Thread
Results 1 to 3 of 3

Add date to filename from cell value with VBA

  1. #1
    Registered User
    Join Date
    06-25-2020
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    365 ProPlus
    Posts
    0

    Question Add date to filename from cell value with VBA

    Hi all,

    I am new to using VBA and stumbled on my code. For work I need to create and save multiple sheets as pdf several times a month. As this is very time consuming I start using VBA to automate the process. At the moment I succeeded in creating and saving the sheets as pdf in a chosen folder. I want the pdf filename to be the value in sheet "Settl Dates" cell D6 (which is a date) and the ActiveSheet name. However somehow I am getting errors when using a date in the filename. For security reasons I have changed my path name, just now that my current path does work. Below my current code:

    Private Sub CommandButton1_Click()
    total_sheets = Worksheets.Count

    For i = 12 To 17

    Worksheets(i).Activate

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:="\\PATHNAME\" & Worksheets("Settl Dates").Range("D6") & " " & ActiveSheet.Name & ".pdf", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    Next

    End Sub

    Your assistance will be highly appreciated, regards, Chalieq

  2. #2
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,146
    Hello Chalieq,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    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]

  3. #3
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2010/2019
    Posts
    9,884

    Re: Add date to filename from cell value with VBA

    Hello Chalieq and Welcome to Excel Forum.
    You have posted a question in our introductions forum.
    Please copy your post and use it to start a new thread in one of the Microsoft Office Application Help - Excel Help forum forums.
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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] Macros to save with a filename and date from cell
    By pvwebster in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-14-2018, 08:28 AM
  2. Convert date into filename for linking cell to another file
    By phbryan in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-10-2017, 11:28 AM
  3. SaveAs FileName: Date in Cell
    By melleniam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-14-2016, 04:58 PM
  4. Input the cell value when a criteria is met (from matching filename date)
    By jamewoong in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-11-2013, 11:47 AM
  5. [SOLVED] including a date (value from cell) in a Filename
    By mr_mango81 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-24-2013, 01:36 AM
  6. set filename to <filename-date> on open
    By bob engler in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-13-2006, 12:15 AM
  7. set excel <filename> to <filename-date>
    By bob engler in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2006, 03:25 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