Results 1 to 4 of 4

problem with VBA file naming code

Threaded View

  1. #1
    Registered User
    Join Date
    08-15-2023
    Location
    saudia arabia
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2307 Build 16.0.16626.20170) 64-bit
    Posts
    1

    problem with VBA file naming code

    im new to excel so i hope i explain this well
    i have a workbook with 2 sheets one is named " Contract ' and one is named " Input " so i wrote a code for a button that is in the Input sheet that will print the contents of the " Contract " sheet as pdf, the code worked but when i try to change the file name it wont work
    what is was trying to do was that i wanted the file name to be the value of a cell in the " Input " sheet


    ----------------------------------------------------------------------------------------

    the code that worked :
    ----------------------------------------------------------------------------------------


    Sub CommandButton1_Click()
    Dim PrintFile As String
    
    PrintFile = Application.DefaultFilePath & "" & _
    ActiveWorkbook.Name & ".pdf"
    
    
    Sheets("Contract").Select
    ActiveSheet.PageSetup.PrintArea = "G1:X124"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=PrintFile, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
    End Sub
    ----------------------------------------------------------------------------------------

    the code that wont work:

    ----------------------------------------------------------------------------------------


    Sub CommandButton1_Click()
    Dim PrintFile As String
    
    PrintFile = Range("K24").Value & ".pdf"
    
    
    Sheets("Contract").Select
    ActiveSheet.PageSetup.PrintArea = "G1:X124"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=PrintFile, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
    End Sub
    Last edited by AliGW; 08-15-2023 at 03:54 AM. Reason: Code tags added - please review the forum rules.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] file naming from VBA code exporting to PDF
    By VBA_muddled in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2021, 09:50 AM
  2. [SOLVED] Modify Code to Change File Naming Output
    By JPDutch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2017, 06:16 PM
  3. [SOLVED] Problem with same VB Code used on different file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-07-2013, 08:47 AM
  4. [SOLVED] Problem re-naming a File
    By Rajesg Dutta in forum Excel General
    Replies: 1
    Last Post: 05-03-2013, 09:11 AM
  5. Folder naming + File naming
    By Frozt15 in forum Excel General
    Replies: 2
    Last Post: 07-23-2012, 04:52 AM
  6. csv naming problem
    By blackfolder in forum Excel General
    Replies: 1
    Last Post: 04-03-2011, 05:26 PM
  7. [SOLVED] Problem Naming Worksheet
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2006, 04:35 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