View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Sandy Sandy is offline
external usenet poster
 
Posts: 270
Default Saving to a specific location

Sorry - wrong code should read as follows - but still produces same error at
MkDir after running thro the function

Sub New_Name()

Open_All_Sheets

Application.ScreenUpdating = False

Application.EnableEvents = False

Dim inputText As String

inputText = Application.InputBox("Enter name here", _
"Golfer's Name", , , , , 2)

Sheets("Data Input").Range("D1:H1").Value = inputText

Application.Run "Lock_All_Sheets"

Application.EnableEvents = True

Application.ScreenUpdating = True


Dim Dirname As String
Dirname = "D\Sandy's Documents\All PGA\ Personal Golf Analyser\Personal
Golf Analyser-" & inputText & ""
If Not DirectoryExist(Dirname) Then
MkDir Dirname
End If
'your save line here
ThisWorkbook.SaveCopyAs Filename:="D:Sandy's Documents\All PGA\Personal
Golf Analyser-" & inputText & "\Personal Golf Analyser-" & inputText &
".xls"

'ThisWorkbook.SaveCopyAs Filename:=Dirname & "\testfile.xls"

ThisWorkbook.Close SaveChanges:=False

End Sub

Function DirectoryExist(sstr As String)
'Tom Oglivy
Dim lngAttr As Long
DirectoryExist = False
If Dir(sstr, vbDirectory) < "" Then
lngAttr = GetAttr(sstr)
If lngAttr And vbDirectory Then _
DirectoryExist = True
End If
End Function

Sandy

"Ron de Bruin" wrote in message
...
You can create the folder with code first if it not exist

Sub testing()
Dim Dirname As String
Dirname = "D\Sandy's Documents\All PSA\PSA\" & inputText
If Not DirectoryExist(Dirname) Then
MkDir Dirname
End If
'your save line here
ThisWorkbook.SaveCopyAs Filename:=Dirname & "\testfile.xls"
End Sub


Function DirectoryExist(sstr As String)
'Tom Oglivy
Dim lngAttr As Long
DirectoryExist = False
If Dir(sstr, vbDirectory) < "" Then
lngAttr = GetAttr(sstr)
If lngAttr And vbDirectory Then _
DirectoryExist = True
End If
End Function


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Sandy" wrote in message
...
Thanks Ron

I've just had another thought - is it possible to SaveAs to a folder that
as yet doesn't exist. Eg

"D\Sandy's Documents\All PSA\PSA\(--and then use the "inputText" to
create this folder--)"

Sandy

"Ron de Bruin" wrote in message
...
Hi Sandy

ThisWorkbook.SaveCopyAs Filename:="D:Sandy's Documents\All PSA\PSA-" &
inputText & ".xls"


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Sandy" wrote in message
...
Hi
I have a bit of code as part of a 'Sub'- namely:

ThisWorkbook.SaveCopyAs Filename:="PSA-" & inputText & ".xls"

which saves a copy of a workbook to the same folder that the original
was opened from, in this case -

'D:Sandy's Documents\All PSA'.

How can I adjust this to save the file in a specific location eg

'D:\Sandy's Documents\All PSA\PSA\Excel 95-2003'

Thanks
Sandy