How to use a user form text box value to change the path to save as pdf

Shaunch

New Member
Joined
May 17, 2021
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
I have a user form to add items and save it as a pdf but i need it to save to a certain folder depending on a text box value if the text box value says day then it should be saved in the day folder or if it says night it should save to the night folder there are 3 folders total and all are located in the same location
Thanks in advance for your help
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi, welcome to forum

Its always helpful if you can share the actual code you are trying to modify but as a general idea, something like this maybe?

VBA Code:
Private Sub Shaunch()
    Dim SaveToFolder As String, FileName As String
    
    Const FolderDay As String = "C:\Day\", FolderNight As String = "C:\Night\"
    
    FileName = "myPDFFileName.pdf"
    
    SaveToFolder = IIf(Me.TextBox1.Value = "Day", FolderDay, FolderNight)
    
    
    'Save sheet as PDF
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=SaveToFolder & FileName

End Sub

Dave
 
Upvote 0
Hi, welcome to forum

Its always helpful if you can share the actual code you are trying to modify but as a general idea, something like this maybe?

VBA Code:
Private Sub Shaunch()
    Dim SaveToFolder As String, FileName As String
   
    Const FolderDay As String = "C:\Day\", FolderNight As String = "C:\Night\"
   
    FileName = "myPDFFileName.pdf"
   
    SaveToFolder = IIf(Me.TextBox1.Value = "Day", FolderDay, FolderNight)
   
   
    'Save sheet as PDF
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=SaveToFolder & FileName

End Sub

Dave
Thanks for your answer after looking at it i had an idea which worked using case of thanks again
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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