PDA

View Full Version : Cell content as part of filename



DerElfente
11-28-2019, 09:37 AM
Dear Sirs and Mamdames,

I'm writing a little script for save excel files as PDF file.
The file name should get saved as follows:

worksheet name & "_" & "list" & " " & the first 2 letters from cell D8 & "." & the first 2 letters from cell K8 & ".pdf"
example: June_list Ha.Ne.pdf

but I don't know how to add the first two letters from the cells D8 and K8. How should I do that?
Sorry for my bad English. Here is the important part of my script:



strFile=Replace(Replace (ws.Name, "", ""), ".", "_") _
&"_" _
&"list" _
&"" _
&"the first 2 letters from cell D8" _
&"." _
&"the first 2 letters from cell K8" _
&".pdf"

strFile= ThisWorkbook.Path&"\"& strFile

SamT
11-28-2019, 10:37 AM
strD8 = Left(ws.Range("D8"), 2)

SamT
11-30-2019, 04:29 PM
oops

Paul_Hossler
11-30-2019, 06:25 PM
Maybe




strFile=ws.Name & "_list " & Left(ws.Range("D8"),2) & "." & Left(ws.Range("K8"),2) & ".pdf"


strFile= ThisWorkbook.Path&"\"& strFile

Bob Phillips
12-01-2019, 04:20 AM
Small error Paul, that first "." should be " ".

And guys, it is better to use Application.PathSeparator rather than hardcode the path separator as "", it can be different on some systems.

DerElfente
12-02-2019, 03:32 AM
Thank you SamT, worked for me with following code part:


strFile=Replace(Replace(ws.Name, "", ""), ".", "_") _

&"_" _
&"list" _

&"" _

&Left(Range("D8"), 2) _

&"." _

&Left(Range("K8"), 2) _

&".pdf"

strFile= ThisWorkbook.Path&"\"& strFile




xld where should "Application.PathSeparator" be set? Did you mean like this?


strFile = Replace(Replace(ws.Name, " ", ""), ".", "_") _
& "_" _
& "Präsenzliste" _
& " " _
& Left(Range("D8"), 2) _
& "." _
& Left(Range("K8"), 2) _
& ".pdf"
strFile = ThisWorkbook.Path & Application.PathSeparator & strFile