+ Reply to Thread
Results 1 to 8 of 8

Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

  1. #1
    Registered User
    Join Date
    10-02-2014
    Location
    Canada
    MS-Off Ver
    Windows 7 professional
    Posts
    5

    Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    Hello all,

    I have been searching during 2 days for this problem I have.

    I need to save an Excel form into .PDF format using a cell value. I've tried everything I could see on different forums, I and just don't know why it doesn't work.

    I'm using a first sub macro to choose a path (that works fine), and when the execution arrives at the save as PDF, it gives me an error. (By the way, I am using sub multiple marcros)

    Here is the code that I am using for the two macros:

    Sub FileDialogMethod_01()
    Dim v As Variant
    Dim wb As Workbook
    Dim newPath As String
    With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "ÉTAPE1: selection du dossier"
    .AllowMultiSelect = False
    If .Show = True Then
    newPath = .SelectedItems(1) & "\"
    Else
    MsgBox "Annuler tout"
    End If
    End With
    End Sub

    *****************up to this point, it works fine...then the following is not working!************************
    Sub SaveAsPDF()
    s = Range("n5").Value

    Activeworkbood.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    s, Quality:=xlQualityStandard, IncludeDocProperties _
    :=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
    End Sub

    Thank you

    cmartel815

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    firstly, your code says "activeworkbood" instead of "activeworkbook"
    Please use code tags (the # button) when pasting code so we can read it better.

    This might solve your problem:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 10-02-2014 at 11:24 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    10-02-2014
    Location
    Canada
    MS-Off Ver
    Windows 7 professional
    Posts
    5

    Re: Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    Thank you Arkadi.

    I corrected "activeworkbood" to "activeworkbook". Still won't work.

    I'm new with VBA, and I'm trying so many ways that I didn't realise that mistake. I know it doens't help me!

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    what is the error you get? I ran the code I pasted in a blank book and it worked great. Can you maybe attach your workbook?

  5. #5
    Registered User
    Join Date
    10-02-2014
    Location
    Canada
    MS-Off Ver
    Windows 7 professional
    Posts
    5

    Re: Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    Quote Originally Posted by Arkadi View Post
    what is the error you get? I ran the code I pasted in a blank book and it worked great. Can you maybe attach your workbook?

    Arkadi, I wanted to send the file, but I just realised that the company'system where I work won't let me.

    I don't know what else to do.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    ok, post your "fixed" code and I'll try to find any other problems.
    Please tell me what error you are getting?

  7. #7
    Registered User
    Join Date
    10-02-2014
    Location
    Canada
    MS-Off Ver
    Windows 7 professional
    Posts
    5

    Re: Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    Arkadi, I filled in my cell "n5", and tested your code again, and I can gladly say that it works!!!!

    Many many thanks for helping me

    I think I have to indicate that my problem is solved.

    Best regards,

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: Excel 2007 macro Save .xlsm as .PDF using a cell value in the filename

    Glad it works, yes N5 definitely needs a name for the code to work. To mark solved use "Thread Tools" at the top.

+ 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] Check if file exists and if so save file incremented by 1 e.g. filename(1).xlsm
    By ratdogexcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2014, 01:15 AM
  2. Excel crashes when trying to save one particular xlsm only after running macro
    By duncandhu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2013, 11:10 AM
  3. Replies: 5
    Last Post: 09-13-2012, 09:49 AM
  4. Replies: 2
    Last Post: 08-13-2012, 05:20 PM
  5. Excel 2003 macro working very slow in Excel 2007 (xlsm format)
    By kapil in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-17-2010, 11:26 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