+ Reply to Thread
Results 1 to 3 of 3

Copying information in a cell to use as a PDF file name

Hybrid View

  1. #1
    Registered User
    Join Date
    10-28-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Copying information in a cell to use as a PDF file name

    Hi All,

    I have a spreadsheet for sports stats, where I run two macros to show information for a particular team match-up.

    Once the information for the two teams is displayed, I would like to utilize a macro(s) to be able to print selected areas of the worksheet to a PDF, copying the details of a nominated cell (say A1) to use as the name of the PDF. The details of this particular cell change depending upon which teams are displayed.

    This is easy enough to do manually, however I am unable to replicate what I do manually via a macro. Is there any way of copying the details within the nominated cell and using this to name this file as part of the print to PDF process.

    Any assistance would be greatly appreciated.

    Thanks,

    Mr N

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copying information in a cell to use as a PDF file name

    here is code that will save your pdf into C:\Temp and name it based on what is in A1
    Sub SaveAsPDf()
    
    Dim strFileName As String
    Const strPath As String = "\Temp\"
    
        strFileName =  Range("A1") 
        
        
        ChDrive "C:\"
        ChDir strPath
        
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, IgnorePrintAreas:=False, OpenAfterPublish:=False
            
    End Sub
    of course change as required

    ps you dont need to have that CHDRIVE/CHDIR in there if you dont want
    you can just add it directly into the file name...like so

    Sub SaveAsPDf()
    
        Dim strFileName As String
        strFileName = Range("A1")
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\temp\" & strFileName, IgnorePrintAreas:=False, OpenAfterPublish:=False
            
    End Sub
    in fact you can shorten it even more to

    Sub SaveAsPDf()
    
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\temp\" & Range("A1"), IgnorePrintAreas:=False, OpenAfterPublish:=False
            
    End Sub
    Last edited by humdingaling; 04-27-2017 at 08:48 PM.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    10-28-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Copying information in a cell to use as a PDF file name

    Thanks so much for taking the time to reply humdingaling.

    I'll give your suggestion a try now.

    Thanks again.

    Mr N

+ 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. Replies: 4
    Last Post: 05-03-2015, 10:30 AM
  2. Copying cell information based on date
    By Ashby1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-30-2014, 02:33 PM
  3. Automate searching and copying information from a file to another
    By d1rt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-28-2012, 02:33 PM
  4. Copying cell information to multiple sheets
    By jdardard@gmail.com in forum Excel General
    Replies: 1
    Last Post: 02-28-2012, 09:47 AM
  5. Selecting / Copying information from another file.
    By lockye in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2008, 12:29 PM
  6. [SOLVED] Copying information from one cell to another without modifying it.
    By akkrug in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 07-27-2006, 02:50 PM
  7. Comparing and copying information from one cell to another
    By ccoverne in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-28-2006, 12:55 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