Making A Folder to place a text file in Code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    Making A Folder to place a text file in Code

    Hi there i was wondering how you make a folder in code to place a text document. another words, i want to create a folder for a text file i create so when iim done with writing the txt file it will create a folder to store it in. But i don't know how to do this this is my code.

    Create My Folder:

    Code:
    Private Sub newfolder()
        'This is the folder I want to create
    '----------------------------------------------------------------------
        Dim ofilesys As New FileSystemObject
        Dim ofolder As Folder
        Set ofolder = ofilesys.CreateFolder("C:\Program Files\MyDiary")
    End Sub
    Place Folder In this But Where?

    Code:
    Private Sub SaveToLog()
    
    ' I want the created folder to be in here somewhere but WHERE!
    '-------------------------------------------------------------
    Dim ff
    ff = FreeFile
    Open "C:\MyDiary.txt" For Append As #ff
    Print #ff, vbNewLine; "Name" & " " & User; vbNewLine _
    & " " & "Subject" & "  " & Subject; vbNewLine _
    & " " & "Date" & "  " & DateOfEntry; vbNewLine _
    & " " & "Log Entry: " & "  " & Log; vbNewLine _
    ; vbNewLine; DiaryLog & "  " & vbNewLine; Now(); vbNewLine
    Close #ff
        Shell "Notepad.exe C:\MyDiary.txt", vbNormalFocus
        DiaryLog.Text = ""
        User.Text = ""
        Log.Text = ""
        Subject.Text = ""
        User.SetFocus
    End Sub
    I hope this explains it all if not tell me and i will try again.

    lee123
  • lee123
    Contributor
    • Feb 2007
    • 556

    #2
    doesn't anybody know how to do this, on this site...

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      Use this code, to make folder (Code without FSO) :

      [code=vb]
      Dim FoldName As String
      FoldName = "C:\MyFolde r"
      If Trim(Dir(FoldNa me,vbDirectory) ) ="" Then
      MkDir FoldName
      End if
      [/code]

      Regards
      Veena

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #4
        ok i have put this in the code. i hope it's in the right area, but how do i put the text file in there (Folder)

        Code:

        Code:
        Private Sub SaveToLog()
            Dim MyDiary As String
            Dim ff
            ff = FreeFile
                Open "C:\My Diary.txt" For Append As #ff
                Print #ff, "Name" & "  " & User; vbNewLine _
                    & " " & "Subject" & "   " & Subject; vbNewLine _
                    & " " & "Date" & "   " & DateOfEntry; vbNewLine _
                    & " " & "Log Entry: " & "   " & Log; vbNewLine _
                    ; vbNewLine; DiaryLog & "   " & vbNewLine; Now(); vbNewLine
                Close #ff
                    Shell "Notepad.exe C:\My Diary", vbNormalFocus
                    DiaryLog.Text = ""
                    User.Text = ""
                    Log.Text = ""
                    Subject.Text = ""
                    User.SetFocus
           
                    MyDiary = "C:\MyDiary"
                    If Trim(Dir(MyDiary, vbDirectory)) = "" Then
                        MkDir MyDiary
                    End If
        End Sub
        lee123

        Comment

        • lee123
          Contributor
          • Feb 2007
          • 556

          #5
          Since there is no response i guess this isn't possible to do.

          thanks anyway!!!!

          lee123

          Comment

          Working...