+ Reply to Thread
Results 1 to 8 of 8

File name based on cell value not working

Hybrid View

  1. #1
    Registered User
    Join Date
    04-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    33

    File name based on cell value not working

    Hi all

    For some reason the file name is not working with a reference to cell H6. Cell H6 is a date value.

    If anyone could help that would be greatly appreciated.

    Thanks

    Sub SendPDF()
    
    ' Create PDF of active sheet and send as attachment.
    '
        Dim strPath As String, strFName As String
        Dim OutApp As Object, OutMail As Object
        
        ActiveSheet.PageSetup.PrintArea = "$A:$J"
        
         'Create PDF of active sheet only
        strPath = Environ$("temp") & "\" 'Or any other path, but include trailing "\"
        
        strFName = ActiveWorkbook.Name
        strFName = Left(strFName, InStrRev(strFName, ".") - 1) & Range("H6") & ".pdf"
        
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            strPath & strFName, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

  2. #2
    Registered User
    Join Date
    09-16-2011
    Location
    Santa Clara, CA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: File name based on cell value not working

    try Range("H6").Value

    GP

  3. #3
    Registered User
    Join Date
    04-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: File name based on cell value not working

    Hey mate

    Thanks for the response. It hasn't worked and when it goes to the de-bugger it highlights the following paragraph in yello.

    not sure if t

  4. #4
    Registered User
    Join Date
    09-16-2011
    Location
    Santa Clara, CA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: File name based on cell value not working

    You are welcome. You will also need to specify sheet. For example activesheet.range("h6").value. GP

  5. #5
    Registered User
    Join Date
    04-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: File name based on cell value not working

    hey mate

    Still won't work.

    Same issue again, highlights the following paragraph.

    Sub SendPDF()
    
    ' Create PDF of active sheet and send as attachment.
    '
        Dim strPath As String, strFName As String
        Dim OutApp As Object, OutMail As Object
        
        ActiveSheet.PageSetup.PrintArea = "$A:$I"
        
         'Create PDF of active sheet only
        strPath = Environ$("temp") & "\" 'Or any other path, but include trailing "\"
        
        strFName = ActiveWorkbook.Name
        strFName = Left(strFName, InStrRev(strFName, ".") - 1) & ActiveSheet.Range("H6").Value & ".pdf"
        
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            strPath & strFName, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

  6. #6
    Registered User
    Join Date
    09-16-2011
    Location
    Santa Clara, CA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: File name based on cell value not working

    Hi again. Date value in cell H6 will need to be converted to a string (without "/" characters) to be valid as a filename.

  7. #7
    Registered User
    Join Date
    04-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: File name based on cell value not working

    Thanks a lot guys, worked a treat.

  8. #8
    Registered User
    Join Date
    04-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: File name based on cell value not working

    That makes sense. Thanks heaps for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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