• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Saving PDF in subfolder

haai

New Member
I have a folder called PDF, in there there are subfolders
I like to save the pdf to the subfolder that is in a sheet Textbox.
How do I change
Code:
strFile = ThisWorkbook.Path & "\PDF\" & Sheets("Sheet1").Textbox1 & "  (" & Format(Now(), "dd-mm-yyyy") & ")" & ".Pdf"
into something like this,where TextBox2 is the name of the subfolder where the PDF should be saved.
Code:
strFile = ThisWorkbook.Path & "\PDF\Sheets("Sheet1").Textbox2\" & Sheets("Sheet1").Textbox1 & "  (" & Format(Now(), "dd-mm-yyyy") & ")" & ".Pdf"
 

haai

New Member
Situation-> Folder (PDF) -> Subfolders (subfolder1, subfolder2, Subfolder3, etc....)
Situation on sheet
Textbox1.value= Chandoo
Textbox2.value= subfolder2
Sheet should be saved as Chandoo with date in subfolder2
If Textbox2 value should be subfolder15 then the file should be save in subfolder 15 and so on.
 

vletm

Excel Ninja
haai
Do You try to explain that Your the 1st code do not work as You have an idea?
Try to send here the exact path to where something should save?
... and with which name?
Do above two answers - without any those 'code's used variables or so.
 

haai

New Member
My first code works just fine,the only thing that I want is that instead the sheet is saved in the Folder PDF it should be saved in a subfolder of the folder PDF
The subfolder should be the one that is in textbox2 on the sheet.
 

vletm

Excel Ninja
haai
I asked 'something' in #2 reply ... You replied (#3) as 'otherwise' ... so far, okay.
with #5 reply ... I try to figure that ... You should reply (#3) as 'Yes, it works' and continue with my hint - hmm?
with #4 reply ... I tried to ask something based Your '#3 reply' ... but ... Should I find those answers from You #5 reply?
> Did You test my 'hint' with #2 reply? Yes/No?
 

vletm

Excel Ninja
haai
I see ...
This is a challenge for me!
If You're answering like 'No' and You would mean 'Yes'.
and finally I tried to ask 'Yes/No' ... I missed that answer.
If I could get any proper answer which could help, You then I could try to help ...
Take Care
 

haai

New Member
I don't know how to explain more.
This code works and saves a sheet as PDF in de PDF folder
Code:
strFile = ThisWorkbook.Path & "\PDF" & "\ " & Sheets("Sheet1").TextBox1 & "  (" & Format(Now(), "dd-mm-yyyy") & ")" & ".Pdf"
Sheets("Sheet1").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
I want to ad some code that saves the sheet in a subfolder of the PDF folder. And the subfolder should be the one that is in Textbox2
 

haai

New Member
See example. (excel file and folder structure)
Instead of the file saved in PDF folder,it should be saved in the subfolder that is in textbox 2.
 

Attachments

Keetoowah

New Member
Hi haai,;)
try this code, don't use ThisWorkbook.Path but write the full path in the first variable (Folder):
Code:
Private Sub CommandButton1_Click()

    Dim Folder As String
    Dim Subfolder As String
    Dim MyFile As String

    Folder = "Myfolder\" & Sheets("Sheet1").TextBox1.Value & "\PDF\" '<<================ Adapt the path
    Subfolder = Sheets("Sheet1").TextBox2.Value & "\"
    MyFile = "(" & Format(Now(), "dd-mm-yyyy") & ")" & ".PDF"
   
    strFile = Folder & Subfolder & MyFile
   
    Sheets("Sheet1").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                                         IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 
Last edited:
Top