![]() |
Mkdir with 2 variables not working ....
Hi -
I've got some code that I've used in a previous workbook that allows a user to save a file to specified drive, using info from the file itself to build the file path and name. The previous version of the code (way below) only used one variable in building the path/name, while the current one uses 2 variables -- the addition of the 2nd variable appears to be causing the problem... The code below is my most recent attempt at making this work -- I've already tried a bunch of different variations of the code: Private Sub SubmitFcst_Click() Dim Drive As Long Dim Path As String, Per As String, Bus As String, NewPath As String Dim Store As String, NewFile As String, NewPath2 As String Store = Format(Sheets("Dashboard").Range("E13").Value, "000") Bus = Sheets("Dashboard").Range("J15").Value Per = Sheets("Dashboard").Range("i5").Value Path = "\\....\Store Forecasts\FY08\" 'actual code specifies entire drive path NewPath = Path & Per & "\" NewPath2 = NewPath & Bus & "\" NewFile = NewPath2 & "Forecast_" & Bus & Store & "_" & Per & ".xls" ' <misc code used to verify user's intent to save remotely and ensure all necessary info is entered 'Make folder to hold new Forecast file If Dir(NewPath2, vbDirectory) = "" Then MkDir NewPath2 ' the line above gives an Error 76: unable to find specified path, with the Mkdir code highlighted ... I also tried MkDir (NewPath2) ... ORIGINAL code: If Dir(Path & Per, vbDirectory) = "" Then MkDir (Path & Per) Is there a limit to how many variables can be used in building the filename? All help is greatly appreciated .... //ray |
Mkdir with 2 variables not working ....
No limit anywhere close to 2
you can't create multiple levels of folders with mkdir if more than one level doesn't exist. say you have a brand new drive with only the c:\ directory (root), no sub directories. You can't do Mkdir "C:\Folder2\SubFolder1" You would have to do Mkdir "C:\Folder2" mkdir "C\Folder2\SubFolder1" I don't know if that is your problem or not. -- Regards, Tom Ogilvy "Ray" wrote: Hi - I've got some code that I've used in a previous workbook that allows a user to save a file to specified drive, using info from the file itself to build the file path and name. The previous version of the code (way below) only used one variable in building the path/name, while the current one uses 2 variables -- the addition of the 2nd variable appears to be causing the problem... The code below is my most recent attempt at making this work -- I've already tried a bunch of different variations of the code: Private Sub SubmitFcst_Click() Dim Drive As Long Dim Path As String, Per As String, Bus As String, NewPath As String Dim Store As String, NewFile As String, NewPath2 As String Store = Format(Sheets("Dashboard").Range("E13").Value, "000") Bus = Sheets("Dashboard").Range("J15").Value Per = Sheets("Dashboard").Range("i5").Value Path = "\\....\Store Forecasts\FY08\" 'actual code specifies entire drive path NewPath = Path & Per & "\" NewPath2 = NewPath & Bus & "\" NewFile = NewPath2 & "Forecast_" & Bus & Store & "_" & Per & ".xls" ' <misc code used to verify user's intent to save remotely and ensure all necessary info is entered 'Make folder to hold new Forecast file If Dir(NewPath2, vbDirectory) = "" Then MkDir NewPath2 ' the line above gives an Error 76: unable to find specified path, with the Mkdir code highlighted ... I also tried MkDir (NewPath2) ... ORIGINAL code: If Dir(Path & Per, vbDirectory) = "" Then MkDir (Path & Per) Is there a limit to how many variables can be used in building the filename? All help is greatly appreciated .... //ray |
Mkdir with 2 variables not working ....
That's exactly it Tom ... thanks very much!
ray |
All times are GMT +1. The time now is 02:15 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com