Code for saved name of pdf file

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,199
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Something simple but its got me.

Currently the saved PDF file is as follows JUNE 06 2021 (2) BUT i would like it to be saved as 06 JUNE 2021 (2)

This is the line of code in use.
Rich (BB code):
 strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\INCOME 2021-2022\" & Range("A3") & " " & Format(Month(DateValue(Range("A3") & " 1, " & "2021")), "00") & " " & Range("D3") & " " & Range("E3") & ".pdf"

On my worksheet i have the following from where the values are taken from.

A3 = JUNE

D3 = 2021

E3 = (2)
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Here is the full code.
Im interested on the code that the file is named once saved

Rich (BB code):
Private Sub SecondMonthsSheet_Click()
    Dim strFileName As String
    
       
       strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\INCOME 2021-2022\" & Range("A3") & " " & Format(Month(DateValue(Range("A3") & " 1, " & "2021")), "00") & " " & Range("D3") & " " & Range("E3") & ".pdf"
                                                                          
       
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GRASS CUTTING INCOME SHEET " & Range("A3") & " " & Range("E3") & " " & Range("D3") & " WAS NOT SAVED AS IT ALREADY EXISTS", vbCritical + vbOKOnly, "INCOME SUMMARY GRASS SHEET MESSAGE"
    
        Exit Sub
    End If
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
        MsgBox "GRASS CUTTING INCOME SHEET " & Range("A3") & " " & Range("E3") & " " & Range("D3") & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "INCOME SUMMARY GRASS SHEET MESSAGE"
        Range("A5:B30").ClearContents
        Range("A3").ClearContents
        Range("A5").Select
        Range("A5:A30").NumberFormat = "@"
        ActiveWorkbook.Save
        INCOMEMONTHYEAR.Show
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,953
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top