+ Reply to Thread
Results 1 to 8 of 8

Getting Run-time Error with Code to save Sheet as PDF

  1. #1
    Registered User
    Join Date
    09-25-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    62

    Getting Run-time Error with Code to save Sheet as PDF

    I have a workbook with code to condense a table of data and save.
    I am getting a run-time error when the code tries to save as a PDF.
    The code works sometimes and sometimes it doesn't.
    I am not schooled in Excel, I hacked together this is code from searches on the web in an effort to create a form for my boss.
    Any and all help with this issue will be appreciated!

    Macro should save Sheet2 with cell Sheet2 F8's value as the documents name in target folder.. after condensing a list.

    Please Login or Register  to view this content.
    Attached Images Attached Images

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,511

    Re: Getting Run-time Error with Code to save Sheet as PDF

    I've put your code in a dummy workbook and it works fine.

    Things that I think may cause an issue are F8 not containing anything or containing something that wouldn't make a valid file name.

    Without an example workbook it's difficult to diagnose the issue.

    BSB

  3. #3
    Registered User
    Join Date
    09-25-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    62

    Re: Getting Run-time Error with Code to save Sheet as PDF

    Thanks BSB for taking a look.

    Attaching the workbook.

    Input 173 in A1 Sheet1 enter
    Input X in column C
    Input job# and Part# then close

    Thanks!
    Slide1

    P.S. I have changed F8 to B2 since this upload.
    F8 reffered to Sheet1.
    Attached Files Attached Files
    Last edited by SLIDE1; 07-11-2018 at 09:55 AM.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,511

    Re: Getting Run-time Error with Code to save Sheet as PDF

    I'm assuming when you save the file as a PDF you are using the Job# from F8 on Sheet1 as the file name?

    If so then you need to change this line of code:
    Please Login or Register  to view this content.
    To:
    Please Login or Register  to view this content.
    At the moment it is looking for a file name in F8 on Sheet2. If that cell is empty then it throws up the error.

    BSB

  5. #5
    Registered User
    Join Date
    09-25-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    62

    Re: Getting Run-time Error with Code to save Sheet as PDF

    BSB,
    You beat me to it..I had already changed F8 to B2 and it doesn't seem to make a difference.
    I thought the with statement was specifying which sheet to print.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,511

    Re: Getting Run-time Error with Code to save Sheet as PDF

    Using a 'with block' causes everything inside the block (after With X and before End With) to be performed on whatever you specify as X.

    So With Sheet2 will cause everything to happen in relation to Sheet2 unless specified otherwise.

    Try changing:
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    BSB

  7. #7
    Registered User
    Join Date
    09-25-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2013
    Posts
    62

    Re: Getting Run-time Error with Code to save Sheet as PDF

    Thanks BSB !

    That works great! I changed it to Sheet2.Range("B2").Value and it only prints Sheet2 to target folder.

    As always I am very grateful for the help!
    Slide1

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,511

    Re: Getting Run-time Error with Code to save Sheet as PDF

    Happy to assist

    BSB

+ 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. Run-time error 1004 error on Mac only Application.Get.Save.AsFilename
    By Carpinteria Al in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2016, 11:20 AM
  2. [SOLVED] Run-time error '1004' - code failing when on a different sheet
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-10-2016, 12:48 PM
  3. Replies: 2
    Last Post: 02-03-2016, 12:23 PM
  4. Need to add if error code to worksheet change event to stop a run-time error
    By KT99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2014, 03:10 PM
  5. [SOLVED] Run time error in code that extracts data from several sheets into master sheet
    By Hello23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2012, 10:11 PM
  6. Excel 2007 : Run-time Error on Save
    By mcmuney in forum Excel General
    Replies: 0
    Last Post: 11-30-2010, 03:35 AM
  7. Save As code error
    By gshock in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-11-2008, 12: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