+ Reply to Thread
Results 1 to 4 of 4

Thread: macro to save as pdf

  1. #1
    Registered User
    Join Date
    01-20-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    18

    macro to save as pdf

    Hi
    I want to save "sheet2" as a PFD file. I use excel 2007, and my code isn't working and I can't figure out why.
    I wrote this code:

    Public Sub savepage()
    Dim name As String
    '///the name is the path for the new file plus dateisMMDDYYYY for a variable date which is located in sheet2 the U6 cell
    name = "C:\Documents and Settings\user\"dateis" & Sheet2.Range("U6").Value & ".pdf"
    sheet2.ExportAsFixedFormat(xlTypePDF,name,xlQualityStandard)
    End Sub
    I strongly believe it's the way to do this but I get the "Expected:=" error message......
    I don't know what to do please help me!!!

    Benedict
    Last edited by benedictexcel; 02-03-2012 at 03:46 PM.

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,234

    Re: macro to save as pdf

    I suspect it may be that "name" is a reserved word so change that first.

    But ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Registered User
    Join Date
    01-20-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: macro to save as pdf

    sorry, I didn't know that rule, I changed it.
    I changed "name" for "nameofthefile" and it still ain't working

  4. #4
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,234

    Re: macro to save as pdf

    I just recorde a macro to publish a .pdf file.

    ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:="C:\Users\...\Documents\Book1.pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False


    I'd go with:

    sName = "C:\Documents and Settings\user\dateis" & Sheets("Sheet2").Range("U6").Value & ".pdf"
    but not tested


    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0