+ Reply to Thread
Results 1 to 8 of 8

Saving PDF and naming based on Cell Value

  1. #1
    Registered User
    Join Date
    02-18-2025
    Location
    America
    MS-Off Ver
    Excel 2019
    Posts
    51

    Saving PDF and naming based on Cell Value

    Hi everyone,

    I don't know why I never thought of posting this issue here, but I'm trying for the last 3 months to figure out what is it that I do wrong

    This is my file and the relevant code below.

    I made this function (I don't even remember how, LOL ) That when I put the data inside cells and click on SUBMIT, the script will:

    Compile a PDF file containing the table data, save it in the defined folder, and created a hyper link in "Data sheet" that I can recall this PDF file when I want.

    The Problem I have is with NAMING. I simply want the file to be named: The service type (e.g. Lunch, Breakfast etc) and the date.

    The service type is in P6 and the date is in J6 (Right now you see in the code something else because it crashes)

    No matter what I do, I get an error when the script is trying to save two cell values that one of them is a date. I tries EVERYTHING!! nothing works

    I would highly appreciate any assistance here


    Sampl 2.8.xlsm


    Please Login or Register  to view this content.

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,175

    Re: Saving PDF and naming based on Cell Value

    Possibly because the date contains / which can't be used in the file name?

    Try formatting it differently:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-18-2025
    Location
    America
    MS-Off Ver
    Excel 2019
    Posts
    51

    Re: Saving PDF and naming based on Cell Value

    I tried that many times.

    I tried it with changing the VBA similar to what you did.
    I tried to change the cell formatting
    I tried it on a different computer

    I tried everything

    I even tried to place the date on a different cell.

    I keep getting an error and this is what I see when I click on DebugScreenshot 2025-04-29 132046.png

    elad770

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,526

    Re: Saving PDF and naming based on Cell Value

    You have name = name = Sheet1.....
    Only name = Sheet1... is required.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Registered User
    Join Date
    02-18-2025
    Location
    America
    MS-Off Ver
    Excel 2019
    Posts
    51

    Re: Saving PDF and naming based on Cell Value

    I changed what I could. Doesn't work

    Please Login or Register  to view this content.
    Please Help!

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,719

    Re: Saving PDF and naming based on Cell Value

    If you replace this
    Please Login or Register  to view this content.
    with this
    Please Login or Register  to view this content.
    and change this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    does it work then?

    name might be a proprietary word
    The inherent weakness of the liberal society: a too rosy view of humanity.

  7. #7
    Registered User
    Join Date
    02-18-2025
    Location
    America
    MS-Off Ver
    Excel 2019
    Posts
    51

    Re: Saving PDF and naming based on Cell Value

    I made the changes you offered. Doesn't work.

    This is what I'm getting as error

    Please Login or Register  to view this content.
    When I click on Decbug, this is what is highlighted

    Sheet1.Range("A1:T33").ExportAsFixedFormat Type:=xlTypePDF, Filename:=path & name & ".pdf"

    elad770

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,526

    Re: Saving PDF and naming based on Cell Value

    Just tested your code and it works fine for me.
    Which is the error message your receiving ?
    The only thing I can come up with is that there's an error in path.

+ 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. Naming and Saving New Workbooks created through VBA
    By Thing2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2024, 01:00 PM
  2. Naming a tab based on information in certain cell
    By Ekoor in forum Excel General
    Replies: 6
    Last Post: 02-07-2020, 05:44 AM
  3. [SOLVED] Naming PDF output based on cell value
    By Matthew55 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2017, 03:01 PM
  4. [SOLVED] Vba code for saving/naming workbook - predefined name based on cells value
    By mariec_06 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-19-2015, 08:43 AM
  5. naming a file based on cell value?
    By nokia3650 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2006, 02:20 AM
  6. [SOLVED] Naming a workbook WITHOUT saving it?
    By Maury Markowitz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-21-2006, 02:50 PM
  7. [SOLVED] RE: Naming a workbook WITHOUT saving it?
    By Tom Ogilvy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-21-2006, 02:45 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