+ Reply to Thread
Results 1 to 4 of 4

Create filepath if it's not available

  1. #1
    StephanieH
    Guest

    Create filepath if it's not available

    I use the following to save a file to a new folder. How can I have it check
    to see if the filepath exists, and if not go ahead and create the path?

    ActiveWorkbook.SaveAs Filename:= _
    "\\Fl-msjf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\" &
    MyDate & "\Gross Placement Batch Tracks\Product Breakdown\Quaternary GBT
    Prod_Breakdown " & MyDate & ".xls" _
    , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False

  2. #2
    AMDRIT
    Guest

    Re: Create filepath if it's not available

    from
    http://cwashington.netreach.net/depo...tType=vbscript


    Dim oFso

    Set oFso = CreateObject("Scripting.FileSystemObject")

    WScript.Echo MakePath(oFso, "C:\TEMP\FRED\BLOGGS")

    ' MakePath
    ' Arguments:
    ' oFso - Instance of FileSystemObject
    ' sPath - Required path (must be fully qualified)
    ' Returns:
    ' True - Path now exists
    ' False - Path does not exist
    Function MakePath(oFso, sPath)
    ' Default result
    MakePath = False

    ' Fail if drive is not valid
    If Not oFso.DriveExists(oFso.GetDriveName(sPath)) Then Exit Function

    ' Succeed if folder exists
    If oFso.FolderExists(sPath) Then
    MakePath = True
    Exit Function
    End if

    ' Call self to ensure parent path exists
    If Not MakePath(oFso, oFso.GetParentFolderName(sPath)) Then Exit
    function

    ' Create folder
    On Error Resume next
    oFso.CreateFolder sPath
    MakePath = oFso.FolderExists(sPath)
    End function


    "StephanieH" <StephanieH@discussions.microsoft.com> wrote in message
    news:1E0B846D-851B-42C8-8C75-CEE60D3CBFBA@microsoft.com...
    >I use the following to save a file to a new folder. How can I have it
    >check
    > to see if the filepath exists, and if not go ahead and create the path?
    >
    > ActiveWorkbook.SaveAs Filename:= _
    > "\\Fl-msjf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\" &
    > MyDate & "\Gross Placement Batch Tracks\Product Breakdown\Quaternary GBT
    > Prod_Breakdown " & MyDate & ".xls" _
    > , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    > ReadOnlyRecommended:=False, CreateBackup:=False




  3. #3
    David Lloyd
    Guest

    Re: Create filepath if it's not available

    Stephanie:

    VBA contains a Dir function for examining files and directories, and a MkDir
    function for creating directories. If you pass the folder path to the Dir
    function, it will return an empty string ("") if it does not exist. Both
    functions are documented in VBA Help.

    --
    David Lloyd
    MCSD .NET
    http://LemingtonConsulting.com

    This response is supplied "as is" without any representations or warranties.


    "StephanieH" <StephanieH@discussions.microsoft.com> wrote in message
    news:1E0B846D-851B-42C8-8C75-CEE60D3CBFBA@microsoft.com...
    I use the following to save a file to a new folder. How can I have it check
    to see if the filepath exists, and if not go ahead and create the path?

    ActiveWorkbook.SaveAs Filename:= _
    "\\Fl-msjf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\" &
    MyDate & "\Gross Placement Batch Tracks\Product Breakdown\Quaternary GBT
    Prod_Breakdown " & MyDate & ".xls" _
    , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False



  4. #4
    StephanieH
    Guest

    RE: Create filepath if it's not available

    Got it working. Thanks for your help AMDRIT and David.



    "StephanieH" wrote:

    > I use the following to save a file to a new folder. How can I have it check
    > to see if the filepath exists, and if not go ahead and create the path?
    >
    > ActiveWorkbook.SaveAs Filename:= _
    > "\\Fl-msjf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\" &
    > MyDate & "\Gross Placement Batch Tracks\Product Breakdown\Quaternary GBT
    > Prod_Breakdown " & MyDate & ".xls" _
    > , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    > ReadOnlyRecommended:=False, CreateBackup:=False


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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