Create folder & name it using value in worksheet cell

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I am using the following code supplied below.
The line of code in Red is where i am stuck at, currently it saves the file of which looks like example 1

Im looking to go one step more in that when the code is run i would like to create a folder,rename it as from valuw in cell C3 & then put this saved pdf inside it.

Please see example 2


Please look at screen shots supplied

Rich (BB code):
Private Sub GrassSummarySheet_Click()
    Dim strFileName As String
    
       strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\SUMMARY SHEETS\" & "SUMMARY" & " " & Range("C3") & ".pdf"
       
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GRASS SUMMARY SHEET " & Range("C3") & " WAS NOT SAVED AS IT ALREADY EXISTS", vbCritical + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
        MsgBox "GRASS SUMMARY SHEET " & Range("C3") & " WAS  SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "GRASS SUMMARY SHEET MESSAGE"
        Range("D5:E17").ClearContents
        Range("D21:E33").ClearContents
        Range("C5").Select
        ActiveWorkbook.Save
    End With
End Sub
 

Attachments

  • EaseUS_2024_01_ 1_09_28_28.jpg
    EaseUS_2024_01_ 1_09_28_28.jpg
    17.1 KB · Views: 13
  • EaseUS_2024_01_ 1_09_28_53.jpg
    EaseUS_2024_01_ 1_09_28_53.jpg
    15.2 KB · Views: 14

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
The line of code below will make the new folder BUT can you advise how i name it using the value from worksheet cell C£

Rich (BB code):
MkDir "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\SUMMARY SHEETS\ & Range("C3") "
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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