+ Reply to Thread
Results 1 to 13 of 13

ActiveSheet will not export to PDF - runtime error 5

  1. #1
    Registered User
    Join Date
    03-17-2011
    Location
    Atlanta
    MS-Off Ver
    Excel for Office 365
    Posts
    38

    Lightbulb ActiveSheet will not export to PDF - runtime error 5

    I have a macro that takes a certain tab, changes the variables, copies the sheet and the prints the individual sheets to PDF. I have used this in more than one workbook successfully, however, when I tried to update another file this morning, I receive the runtime 5 error when it gets to the red portion. I have tested the other workbooks with this code and it works perfectly.

    I have resaved the file as macro enabled workbook and checked the code is identical in all workbooks. Does anyone have any suggestions on file settings to tweak that may be causing the issue? I know the code itself should not be the problem as it works perfectly in other workbook files.


    Please Login or Register  to view this content.
    Last edited by physicsgal; 01-28-2016 at 03:32 PM. Reason: Solved

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ActiveSheet will not export to PDF - runtime error 5

    Removed because when I edited it, for some reason it appeared in post # 3
    Last edited by gmr4evr1; 01-27-2016 at 04:14 PM.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ActiveSheet will not export to PDF - runtime error 5

    I haven't seen the desktop = call out before so I could be wrong about this, but usually in "mypath" there has to be a drive letter included
    Please Login or Register  to view this content.
    or maybe
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-17-2011
    Location
    Atlanta
    MS-Off Ver
    Excel for Office 365
    Posts
    38

    Re: ActiveSheet will not export to PDF - runtime error 5

    I don't think that's the case because it still works in the three other files I've added it to. I would upload the file, but there is a lot of proprietary information. I was hoping there were some settings in the file I could tweak. All the files I have compared to have been the same, so I'm not sure what it does not export.

  5. #5
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ActiveSheet will not export to PDF - runtime error 5

    My mistake, I didn't read your post fully, sorry about that.
    Should
    Please Login or Register  to view this content.
    be
    Please Login or Register  to view this content.
    I tried to use your code in a blank workbook to see if I could recreate the error, but, not all of the code is there so it's being very difficult.
    Edit* It looks as if all your Physician words are missing quotes.
    Last edited by gmr4evr1; 01-27-2016 at 04:49 PM. Reason: Added edit

  6. #6
    Registered User
    Join Date
    03-17-2011
    Location
    Atlanta
    MS-Off Ver
    Excel for Office 365
    Posts
    38

    Re: ActiveSheet will not export to PDF - runtime error 5

    Yea, I will post the full code below, so others can try. Physician is actually a defined variable, as there are many throughout the schedules and I am printing an individual schedule for each of the physicians in the file.

    The code runs until it hits the section which wants to export it as a PDF.

    Please Login or Register  to view this content.
    Last edited by physicsgal; 01-28-2016 at 03:14 PM. Reason: Etiquette

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ActiveSheet will not export to PDF - runtime error 5

    Hmmmm...Interstingly enough, as long as I had something in range A9:A24 of the Modeling Detail sheet, it ran perfectly fine.

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: ActiveSheet will not export to PDF - runtime error 5

    Please click the # icon and paste code between code tags. You should edit your posts to do that.

    Before that error I would put this:
    Please Login or Register  to view this content.
    When you run the code, the values above are put into the Immediate window of the VBE. You may see the problem there.

    Your code is partial so we can't see that you must have defined the value of Physician before the loop. You have Activate and Select in places where they are likely not needed.

    You may need to check for the worksheet existing before you use it. We can show you that if needed. e.g. Worksheet names can not be "" nor have illegal characters.

  9. #9
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ActiveSheet will not export to PDF - runtime error 5

    Check to be sure that the sheet names that it is trying to create do not already exist. When I ran the code a second time with the same values/text in the A9:A24 range, it would error out for me where you are getting the error because it cannot create the same sheet name more than once. Once I deleted those sheet names, or changed the values/text in A9:A29, it worked fine.

  10. #10
    Registered User
    Join Date
    03-17-2011
    Location
    Atlanta
    MS-Off Ver
    Excel for Office 365
    Posts
    38

    Re: ActiveSheet will not export to PDF - runtime error 5

    I will try this. Please see post #6 for the full code.

  11. #11
    Registered User
    Join Date
    03-17-2011
    Location
    Atlanta
    MS-Off Ver
    Excel for Office 365
    Posts
    38

    Re: ActiveSheet will not export to PDF - runtime error 5

    Quote Originally Posted by gmr4evr1 View Post
    Check to be sure that the sheet names that it is trying to create do not already exist. When I ran the code a second time with the same values/text in the A9:A24 range, it would error out for me where you are getting the error because it cannot create the same sheet name more than once. Once I deleted those sheet names, or changed the values/text in A9:A29, it worked fine.
    Yea, I am aware of the issue. When I developed this, we had a client who needed to have the excel version as well as the PDFs. I typically delete them out before saving or running a new version.

    I will check on Kenneth's suggestion that there may be illegal characters in the names since I am pulling from a list.

  12. #12
    Registered User
    Join Date
    03-17-2011
    Location
    Atlanta
    MS-Off Ver
    Excel for Office 365
    Posts
    38

    Talking Re: ActiveSheet will not export to PDF - runtime error 5

    I updated the issue to solved. Thanks to both of you for your suggestions and help.

    The problem was that there was a hidden tab I was not aware of that was the same name as one of the physicians I was trying to print.

  13. #13
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ActiveSheet will not export to PDF - runtime error 5

    Glad you got it worked out!

+ 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] Getting error on ActiveSheet.PageSetup.PrintArea - how do I fix error
    By cmwilbur in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2014, 03:25 PM
  2. Simple Activesheet.paste will not work (Runtime 1004 error)
    By yjung15 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2013, 02:42 PM
  3. ActiveSheet.Paste failing(Runtime error '1004')
    By sanjeevap in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2013, 12:58 PM
  4. Macro to export webpage data into the activesheet rather than a new file
    By naqviimran in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2011, 12:21 AM
  5. Export strPath - Runtime Error 70 - Permission Denie
    By EDR in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2009, 03:08 AM
  6. excel chart export error runtime 1004
    By Mau in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-17-2005, 07:05 AM
  7. excel chart export error runtime 1004
    By Mau in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2005, 05:05 PM

Tags for this Thread

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