W
William Hamilton
I have an app where there is a templete that resides in a directory,
under this directory is a data storage folder, the location of the
template can change. Part of the code builds the require directory
structure below the template location.
Is there a way to set the curdir to where the workbook was opened from
ie: where template sits? I am interupting the save process so I can set
the name of the file depending on values within a worksheet, it needs to
default to the "place where template is"\datastore\"Name I define".xls
TIA
W
Code below FYI:
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'error trap
On Error GoTo Etrap
Dim MyCell, mySavePath, mySaveName
MyCell = Range("Summary!B6")
mySavePath = CurDir & "\datastore\"
mySaveName = mySavePath & MyCell
'MsgBox (CurDir & "\datastore\" & MyCell)
' confirm the datastore directory exists, if not create it.
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.folderexists(mySavePath) Then
Else
FSO.createfolder (mySavePath)
End If
'check value of activecell
If MyCell = "0" Then
MsgBox "Please check you have a candidate name", vbInformation
Exit Sub
End If
'ask user to save
'If MsgBox("Save new workbook as " & CurDir & "\datastore\" &
MyCell & ".xls?", vbYesNo) = vbNo Then
'Exit Sub
'End If
'save activeworkbook as new workbook
ActiveWorkbook.SaveAs Filename:=mySaveName & ".xls",
FileFormat:=xlNormal
Etrap:
Beep
Exit Sub
under this directory is a data storage folder, the location of the
template can change. Part of the code builds the require directory
structure below the template location.
Is there a way to set the curdir to where the workbook was opened from
ie: where template sits? I am interupting the save process so I can set
the name of the file depending on values within a worksheet, it needs to
default to the "place where template is"\datastore\"Name I define".xls
TIA
W
Code below FYI:
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'error trap
On Error GoTo Etrap
Dim MyCell, mySavePath, mySaveName
MyCell = Range("Summary!B6")
mySavePath = CurDir & "\datastore\"
mySaveName = mySavePath & MyCell
'MsgBox (CurDir & "\datastore\" & MyCell)
' confirm the datastore directory exists, if not create it.
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.folderexists(mySavePath) Then
Else
FSO.createfolder (mySavePath)
End If
'check value of activecell
If MyCell = "0" Then
MsgBox "Please check you have a candidate name", vbInformation
Exit Sub
End If
'ask user to save
'If MsgBox("Save new workbook as " & CurDir & "\datastore\" &
MyCell & ".xls?", vbYesNo) = vbNo Then
'Exit Sub
'End If
'save activeworkbook as new workbook
ActiveWorkbook.SaveAs Filename:=mySaveName & ".xls",
FileFormat:=xlNormal
Etrap:
Beep
Exit Sub