+ Reply to Thread
Results 1 to 19 of 19

Export to pdf - filename query

  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Export to pdf - filename query

    Hello, I have the following code exports selected contents to a PDF

    Please Login or Register  to view this content.
    Where the macro picks up the client name from a cell, I would also like the end of the filename (where it says 2013 on my code) to be pulled from another cell but can't quite get it right. Can anyone tell mw where i am going wrong?

    Please Login or Register  to view this content.
    doesn't seem to work.

    Also the export is to a folder where the workbook is saved and by default it overwrites any file with the same name. is there a way to prompt in the event of this so the filename may be changed?

    thanks in advance.

  2. #2
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    Maybe check if pdf exists and than adding time stam may work?

    Please Login or Register  to view this content.
    Gerard
    Last edited by G e r a r d; 01-23-2014 at 10:00 AM. Reason: Uncomplete answer

  3. #3
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    Hi, that's a brilliant Idea and exactly what I want but i can't get your code to work. My entire macro selects a different range of pages based on the value of a cell. So, if cell value is 1 select pages X-X, if 2 select X-Y, etc. I think this is why I can't get it working.

    This is my entire code:

    Please Login or Register  to view this content.
    Can you tell me where I am going wrong please?

    thanks,
    dan

  4. #4
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    any ideas would be great?

  5. #5
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    Cant test it but something like this:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    Incredible - you have yourself a good weekend!

    thanks a lot!

  7. #7
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    Hi sorry, I do have another query and if this is more appropriate in a new post please let me know and I will create one:

    THis code above is perfect and is exactly what I need. Is it possible to have a second button which would run exactly the same code but then attach the pdf to an email in outlook ready for sending, and also specify the message subject and content?

  8. #8
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    I cant test it, I don't have Outlook.

    But this may do it...

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    Hi that does generate the report and opens a new email with your message, but doesn't attach the file.

    I have found this other code on a website, which would do exactly what I need but can't get it working:

    Please Login or Register  to view this content.
    thinking that if this bit
    Please Login or Register  to view this content.
    could be changed to pick up all pages that had the number 1 in cell A4 on each work sheet then this might work. But as I have said it doesn't seem to work in my programme? Can you suggest anything?

  10. #10
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    It is falling down here:

    Please Login or Register  to view this content.
    saying compile error - sub or function not defined.

  11. #11
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    Attachment problem, most likely caused by the absents of the .pdf
    This may work:
    Change
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    Gerard

  12. #12
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    Quote Originally Posted by dantray02 View Post
    It is falling down here:

    Please Login or Register  to view this content.
    saying compile error - sub or function not defined.
    RDB_Create_PDF is a function
    Most likely you don't have the function in your project

    Gerard

  13. #13
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    thank you. These are the functions in the workbook I downloaded.

    Please Login or Register  to view this content.
    So using the above, and these two functions, is it possible to export the same worksheets that you have already helped me with and then attach to an email?

  14. #14
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    I found a bug in the code that I put up earlier
    Send was not declared and did not have value....

    At the moment I don't have time to go through the functions and code you provided.

    Gr.
    Gerard

    Note : change Send = True to False if you don't want to send directly. I think the change does the work

    Please Login or Register  to view this content.
    Last edited by G e r a r d; 01-24-2014 at 11:13 AM. Reason: Sub name invalid

  15. #15
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    hi Gerard,

    It still doesn't attach the file. also can you tell me where the file is exported to in the exportandsendpdf code

    thank you for your help.

  16. #16
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    Also gerard, you do not need to look at the function code I provided. yours works fine but I can not get the file to attach.

    Other similar codes send the file to a temporary location and then attach from here. Is there a way to do this?

  17. #17
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    The file is saved in the standard directory of Excel

    You can check the directory :
    Please Login or Register  to view this content.
    It is possible to set a dir for the file to be saved in

    Please Login or Register  to view this content.
    For the no attachment of the pdf....
    Can't debug it, because I don't have Outlook.
    Sorry for that.

    Gerard.
    Last edited by G e r a r d; 01-24-2014 at 12:37 PM. Reason: Add extra code for dir set

  18. #18
    Registered User
    Join Date
    01-08-2014
    Location
    wigan
    MS-Off Ver
    2007
    Posts
    78

    Re: Export to pdf - filename query

    ok thanks. it is saving to my documents - is it possible to get it to save in the folder that contains the workbook?
    Last edited by dantray02; 01-24-2014 at 12:48 PM. Reason: said file instead of folder

  19. #19
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Export to pdf - filename query

    Yes, ad de sDir string variant and create the directory string used by the workbook : ThisWorkbook.Path & "\"

    Add the sDir & just before the sFileName.

    Please Login or Register  to view this content.

+ 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] filename suggestion for tab to CSV export
    By PatRiot199 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-25-2013, 05:57 AM
  2. [SOLVED] Use Name from Cell in FileName export
    By ertweety in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2012, 11:11 AM
  3. Export xml using Macro (Different Filename)
    By Lotskie73 in forum Excel General
    Replies: 0
    Last Post: 11-28-2011, 07:29 PM
  4. Export the workbook filename to Word
    By twofootgiant in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-17-2011, 02:28 PM
  5. Export to HTML filename and filepath
    By magicool in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2009, 05:33 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