Consulting

Results 1 to 11 of 11

Thread: VBA creating new folders and files

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Dec 2018
    Posts
    11
    Location

    VBA creating new folders and files

    Hello all,
    I'm very new here. I have some VBA knowledge but not much. Usually I search and edit codes to fit my needs, but this time I'm stuck and could use some advice.
    Here is what I'm looking to accomplish with my code.
    I currently have a code that creates folders and sub folders using cell value as main folder name. I would like within this same code, to be able to Save As one of the sheets as a new file in one of the newly created sub folders.
    Below is the code I'm using. Works fine and does everything it needs to do.
    I have a tab/sheet named "Test Plan" to be saved under sub folder "Test Info" with the vehicle number from "B1" as name. If its possible to have TP before or after the vehicle number in the name, would be even better. example TP BY1111242.xls or BY1111242 TP.xls

    For some reason, I'm denied to post an excel screen shot.

    Thank you very much!

    Sub MakeFolder()
    Dim strVehNum As String, strPathDefault As String, strFolderTestInfo As String, strFolderPics As String, strFolderServiceComments As String, strFolderPrintouts As String
    Dim FSO As New FileSystemObject
    strVehNum = Range("B1") ' assumes vehicle number in B1
    strPath = "G:\03 PROJECTS\AUTOS"
    strFolderTestInfo = "Test info"
    strFolderPics = "Pics"
    strFolderServiceComments = "Service comments"
    strFolderPrintouts = "Printouts"
    If Not FSO.FolderExists(strPath & strVehNum) Then
        FSO.CreateFolder strPath & strVehNum
        FSO.CreateFolder strPath & strVehNum & "" & strFolderTestInfo
        FSO.CreateFolder strPath & strVehNum & "" & strFolderPics
        FSO.CreateFolder strPath & strVehNum & "" & strFolderServiceComments
        FSO.CreateFolder strPath & strVehNum & "" & strFolderPrintouts
    Else
    End If
        UserName
    End Sub
    Last edited by Aussiebear; 12-15-2018 at 04:01 PM. Reason: Added tags to code

Posting Permissions

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