text file name and path with variable

83 Views Asked by At

I am trying to create macro that can create text file with variable and location of file is where user can choose the path.

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set app = CreateObject("Shell.Application")
Set D = app.BrowseForFolder(0, "Select Folder", 1)
If D Is Nothing Then
    Inp = "C:\"
Else
    Inp = D.Self.Path
    
    
End If


Set oTF = oFSO.CreateTextFile(oFSO.BuildPath("" & Inp & "\" & partdatetime & ".txt", wr, True)) 

i am getting error in last line. here "Inp" is stored path of text where it has to save (user selection). "partdatetime" is file name (name through variable). ca anyone tell me where i missed.

1

There are 1 best solutions below

0
Jörgen R On

There are a number of errors in your last line of code.

  1. It calls BuildPath but then you build it "by hand".
  2. partdatetime has no value
  3. wr has no value and there is no clue of your intentions

Probably you mean to write

partdatetime=Format(Now(),"yyyymmdd_hhnnss")
Set oTF = oFSO.CreateTextFile(oFSO.BuildPath(Inp, partdatetime & ".txt"), True)