Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filepath Marie-Jo Excel Discussion (Misc queries) 3 July 5th 05 07:56 PM
Filepath Marie-Jo Excel Discussion (Misc queries) 2 June 30th 05 11:06 PM
Using a cell reference in a filepath Pinda[_2_] Excel Programming 5 November 9th 04 11:37 PM
get filename and filepath Robert Ehrlich Excel Programming 3 December 21st 03 12:23 PM
Selecting File and FilePath Peter Harrison Excel Programming 2 November 7th 03 04:27 PM


All times are GMT +1. The time now is 09:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"