ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel macro to open Notepad and save with Date/Time in filename (https://www.excelbanter.com/excel-programming/407663-excel-macro-open-notepad-save-date-time-filename.html)

willy

Excel macro to open Notepad and save with Date/Time in filename
 
I've tried to create this macro using the Shell command which works for
opening Notepad but I can't get the part about putting the date and time into
the filename of the Notepad file. The date and time format could have blanks
between such as mm dd yyyy hh mm ss but if it has underscore or other
characters that is ok.

RB Smissaert

Excel macro to open Notepad and save with Date/Time in filename
 
This is a different approach and maybe simpler:

Option Explicit

Sub StringToTextFile(ByVal txtFile As String, _
ByVal strString As String)

Dim hFile As Long

hFile = FreeFile

'Close before reopening in another mode.
'---------------------------------------
On Error Resume Next
Open txtFile For Input As #hFile
Close #hFile

Open txtFile For Output As #hFile
'this will make start- and end quotes
'Write #hFile, strString
Print #hFile, strString;
Close #hFile

End Sub


Sub test()

Dim strFolder As String
Dim strFileName As String
Dim strExtension As String

strFolder = "C:\"
strFileName = "File " & _
Format(Date, "dd_mmm_yyyy")
strExtension = ".txt"

StringToTextFile _
strFolder & strFileName & strExtension, _
"just testing"

End Sub


RBS


"Willy" wrote in message
...
I've tried to create this macro using the Shell command which works for
opening Notepad but I can't get the part about putting the date and time
into
the filename of the Notepad file. The date and time format could have
blanks
between such as mm dd yyyy hh mm ss but if it has underscore or other
characters that is ok.




All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com