How to Dynamic Notepad Titles

Hello guys,

I am trying to create a project that gets the body of an email then dumps it into a notepad. My problem is, how can I replace the title of the notepad as month+date+year_hours+minutes+seconds without the separators(or with period as a separator) coz we all know that the separators can’t be a title at notepad. the title should be like this; 12172018_225834 or 12.17.2018_22.58.34

Thanks in advance for those who’ll reply. :slight_smile:


1 Like


are you asking how do you put the filename or date string in the Selector so it will dump the data into the correct notepad window?

You’ll need to edit the selector as an expression and concatenate the values in the title attribute. You can either store your date time into a variable prior or place the date time directly in the selector.

It will end up looking something like this:
Assign timestamp = Now.ToString("")
"<wnd app='notepad.exe' cls='Notepad' title='*"+timestamp+"*' /><wnd cls='Edit' />"
"<wnd app='notepad.exe' cls='Notepad' title='*"+Now.ToString("")+"*' /><wnd cls='Edit' />"

For more info on how to edit the selector as an expression, you can find some better details throughout the forum like in this topic: Can I use screen scrapping for multiple pdf dynamically? - #8 by ClaytonM

Basically, you will click in the Selector property box instead of the 3 dots, which lets you edit the selector as a string.



To add to @ClaytonM’s answer, you can also use the format Now.ToString("MMddyyyy_hhmmss" for the alternate format when assigning to the timestamp variable to use as the filename for the notepad.



Hi Clayton, my plan is to copy the body of an email, and dump it into an untitled notepad then have the filename of the notepad consist of the timestamp of the email, I think i will be using the mail.Headers(“Date”), can I change the timestamp to Date instead of Now? Coz I think “Now” uses the current date and time?

Yeah. You can use mail.Headers(“Date”), but you just need to parse it to a date so you can format it the way you want. If it is in the “MM/dd/yyyy” format then you can just use Convert.ToDate() or CDate()

So, replace Now with this:

If the date is in the “dd/MM/yyyy” format, then you’ll need to use ParseExact()
I believe it would look like this:
DateTime.ParseExact( mail.Headers("Date").ToString, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)
If I made a mistake on that, there are examples of this on the forum or online

Then, you can format it just like I showed, like .ToString(“MMddyyyy_HHmmss”)
Keep in mind, that “hh” is 12hour format and “HH” is 24hr.



Hi, how can I use a variable as a filename on my notepad?

I’m trying to change it like this. timestamp = mail.Headers(“Date.”.ToString(“MM-dd-yyyy_HH-mm-ss”)), but it returns an error like this one. Sorry, really a newbie here.

There seems to be a typo in the code. I think it should be mail.Headers(“Date”).ToString(“MM-dd-yyyy_HH-mm-ss”)

Can you try that?

still show’s the same error. "Option Strict On disallows conversions from ‘String’ to ‘System.IFormatProvider’.

Can you use a WriteLine Activity to output the value of mail.Headers(“Date”).ToString just to see what value it contains?

I used a message box to display the contents. Basically it’s the time stamp of when the unread email is received as to what my process flow should be doing.

Can you try mail.Headers(“Date”).ToString value replace / and : with . and space with _
Result value you can use to save your notepad file

So, open notepad, paste your email body.
Get your filename using above and then when saving the notepad you can use that as the name.


You can use regex replace Regex.Replace(datevar,"[/|:]",".").Replace(" ","_")

1 Like

where would I put the mail.Headers(“Date”).ToString?

1 Like

you can assign it to a variable like i did ‘datevar’
Regex.Replace(datevar,"[/|:]",".").Replace(" ","_")
or you can simply use the expression:
Regex.Replace(mail.Headers(“Date”).ToString,"[/|:]",".").Replace(" ","_")

1 Like

You will need System.Text.RegularExpressions in your import.
Please add that for Regex

Noted. But how can I use the variable filename for my notepad file name? I used this line of code but it ended up with an error.

"C:\Users\angelo.s.reyes.ii\Desktop\"filename+".txt" it says End of expression expected.

1 Like


Try this


Ooops. Sorry overlooked that one.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.