need code for save button, to take text from textbox1 and use a filename.

Nutsy

New member
Joined
Jul 12, 2018
Messages
4
Reaction score
0
Points
0
Excel Version(s)
2016
I am having a problem finding the code to take the text from textbox1, as in the photo and using the txt as a file name when I print to pdf. Can anyone help please. Thanks in advance or if someone could suggest an all in one save and print button that would even be better.

1.png
 
.
Try this. Saves to same location as workbook :

Code:
Option Explicit


Sub Export_Worksheet_to_PDF()


    Dim mypath As String, fname As String, dname As String
    mypath = ThisWorkbook.Path
    dname = Format(ActiveSheet.Range("B1").Value)
    fname = CreateObject("Scripting.FileSystemObject").GetBaseName(dname)
    ActiveSheet.Range("B3:G17").ExportAsFixedFormat 0, mypath & "\" & fname


End Sub
 

Attachments

  • PDF Save Active Sheet J2 Value as Name.xlsm
    17.2 KB · Views: 5
Back
Top