Date Format Help

rockchalk33

Board Regular
Joined
Jan 12, 2016
Messages
111
Hey all,

So I'm at the tail end of an enormous project and at the end of a subroutine I have a specific sheet being saved as a PDF. This PDF is representing a group of information based on a specific date entered by the user in the mm/dd/yyyy format. This value is entered at the beginning of the sub routine and is shown here:

Code:
Dim userDate As String
userDate = InputBox("Please type a date to search in MM/DD/YYYY format")

My goal is to have the PDF saved as ......../MM_DD_YYYY because saving it as MM/DD/YYYY obviously creates an error as seen in the code below.

Code:
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\Rocky\Desktop\Devin\Project\" & userDate & ".pdf", Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

How can I rewrite the above code to satisfy saving the data as well as representing the arbitrary date entered?

Thanks
 

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)

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
15,053
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Untested but try adding the line below...

Code:
Dim userDate As String
userDate = InputBox("Please type a date to search in MM/DD/YYYY format")
[COLOR="#FF0000"]userDate = Replace(userDate, "/", "_")[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,191,611
Messages
5,987,667
Members
440,104
Latest member
thigarette

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
Top