+ Reply to Thread
Results 1 to 3 of 3

Creating new files and folders

  1. #1
    Forum Contributor
    Join Date
    12-02-2013
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    112

    Creating new files and folders

    Hello everyone,


    Please Login or Register  to view this content.
    By running the above code i did successfully created a file named "1 nov 2014" and saved a new blank word document named "ANSWRS.docx" in it.
    But when i want to create another file named "2 nov 2014" and save a new word document with the same name "ANSWERS.Docx" .
    I have to modify the above code as followes:

    Please Login or Register  to view this content.

    Is it possible to create a new file without changing the file name in the above code and save a new word document named "ANSWERS.Docx" inside that file?
    And also when the "NOV 2014" folder is full, is it possible for the code to automatically create another folder "DEC 2014" and continue creating files "1 dec 2014", "2 dec 2014" etc?

    Cheers
    Last edited by Leith Ross; 12-26-2014 at 12:33 AM. Reason: Added Code Tags

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Creating new files and folders

    Maybe try this

    Please Login or Register  to view this content.
    Martin

  3. #3
    Forum Contributor
    Join Date
    12-02-2013
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Creating new files and folders

    @mrice

    Sub Test()
    Dim myDir As String
    Dim Folder1 As String

    StartDate = DateValue("2-Nov-2014")
    NumberOfDays = 1

    For N = 0 To NumberOfDays - 1
    Folder1 = UCase(Format(StartDate + N, "MMM YYYY"))
    Folder2 = Format(StartDate + N, "DD MMM YYYY")
    If Dir("C:\GRANDVARIATIONS\FILES\" & Folder1, vbDirectory) = "" Then
    MkDir "C:\GRANDVARIATIONS\FILES\" & Folder1
    End If
    If Dir("C:\GRANDVARIATIONS\FILES\" & Folder1 & "\" & Folder2, vbDirectory) = "" Then
    MkDir "C:\GRANDVARIATIONS\FILES\" & Folder1 & "\" & Folder2
    End If




    On Error Resume Next
    Set oDoc = GetObject(sDocPath)
    Set oWord = oDoc.Parent
    If Err <> 0 Then
    Set oWord = CreateObject("Word.Application")
    Set oDoc = oWord.Documents.Add
    End If

    oDoc.SaveAs ("C:\GRANDVARIATIONS\FILES\" & Folder1 & "\" & Folder2 & "\ANSWERS.Docx")
    oDoc.Close

    Next N
    End Sub

    In a "FILES" folder there is already "1-Nov-2014" and by using the above code i became able to create another file named "2-Nov-2014".
    but while creating file named "3-Nov-2014" again i have to change "StartDate = DateValue("2-Nov-2014")" to "StartDate = DateValue("3-Nov-2014")"
    Isn't there a way so that i wont have to change that value every time i want to create a new file?

    note: I would like the code to "iterate over the folders, determine which is the newest one, and then set the variable to that date"
    Last edited by LAVA2; 12-29-2014 at 04:14 PM. Reason: information was missing

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create folders and save text files to these folders
    By bloomingcarrot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2014, 08:14 PM
  2. Use Excel VBA to Copy multiple files from different source folders to different folders
    By mm1234mail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 01:17 PM
  3. Replies: 1
    Last Post: 09-12-2013, 09:23 PM
  4. Archiving Files - Creating New Folders and Moving Files
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2011, 06:47 AM
  5. Create folders and move and copy files into that folders
    By vijaybharthi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2010, 04:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1