Including cell name in file path, mixing hard lines and cells

Jocelin

New Member
Joined
Jun 13, 2018
Messages
10
hello friends,
I wish to make it so that my company's commands automatically get saved in the right folder. I made a template for these commands and I wished to be able to include the cell name in my file path like so: https://stackoverflow.com/questions/20978868/vba-macro-to-save-excel-file-using-path-from-cell

But in my case, i'd like to put the cell name in the path like so: " C:\Users\Vincent.BILLY-SURFACE\Desktop\affaires en cours"nameof the cell in A20"\concombre1\orange 2\bite mole"file name"

Please help, this is something my tutor would like for friday, thank you for your help!
 
Try
Code:
Private Sub SaveSpecific_Click()
   Dim filename1 As String
   Dim Pth1 As String, Pth As String
   
   Pth1 = Dir("C:\Users\Vincent.BILLY-SURFACE\Desktop\affaires en cours\" & Range("A20") & "*", vbDirectory)
   Pth = "C:\Users\Vincent.BILLY-SURFACE\Desktop\affaires en cours\" & Pth1 & "\concombre1\orange 2\bite mole\"
   filename1 = Range("F7").Text
   Application.DisplayAlerts = False
   ActiveWorkbook.SaveAs fileName:=Pth & filename1 & ".xlsx", FileFormat:=xlOpenXMLWorkbook
   Application.DisplayAlerts = True
End Sub
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thanks for the quick response, sadly i am getting the following error:
bX8ecM.png
 
Upvote 0
Which line of code gave that error and what are the exact values of A20 & F7?
 
Upvote 0
2qNuSF.png
Here you can see F7 and A20, I don't think the "-" is creating a problem, you can also see the line of code creating the error
 
Upvote 0
If you hover the mouse over Pth when you get the error, is the path correct?
 
Upvote 0
For some reason there is a double slash after "affaires en cours", i even removed a bunch of \ to see if that would fix it and it didn't, I am guessing the double slash is there to allow range 20 to be there in between but its not.
07tPPM.png
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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