View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
ChasAA ChasAA is offline
external usenet poster
 
Posts: 33
Default Save file in a new folder, but create folder only if folder do

Hello,
Are you replying to Chas or Ron?.

If it is Chas.
You can call the "makeFolder" subroutine but you will have to pass the
appropriate variables.
Or you can insert the line of code after your line where you assign the
filename.
(Incidentally, but I'm sure you figured it out already, in the snippet I
sent you. I was MkDir with your variable names and Saving as C:\Chasdev etc.
Obviously this is wrong.

What you will be doing now is
Attemting to make the new directory.
If there is an error it will be taken care of by the error trap

Once that is done then you can check to see if the file exisits already

But (I'm not sure about this but why not turn DisplayAlerts on and the
system will ask you if you want to overwrite the file).
If you need alerts off just turn them off straight after you have saved the
file.

Chas

"nbaj2k" wrote:


I got this code, my now I'm confused how I would also incorporate into
this how to have it check to see if the file already exists. If it
does I wanted it to ask if it should overwrite or not.

This code was posted in a reply to my other post, but now I'm confused
how I would put them both together. Is there an Else If statement I
would add to it or something?

Thanks,

~J


Public Sub Tester()
Dim FName As String
Const myPath As String = "G:\Reports\First\"
Dim res As VbMsgBoxResult

FName = Range("A1")

If Dir(myPath & FName) < "" Then
res = MsgBox(Prompt:="The file already exists. " _
& "Do you wish to overwrite it?", _
Buttons:=vbYesNo)
End If

If res = vbYes Then
ChDir myPath
ActiveWorkbook.SaveAs filename:=myPath & FName, _
FileFormat:=xlNormal, _
Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=No, _
CreateBackup:=False
Else
'do nothing?
End If
End Sub


--
nbaj2k
------------------------------------------------------------------------
nbaj2k's Profile: http://www.excelforum.com/member.php...o&userid=36480
View this thread: http://www.excelforum.com/showthread...hreadid=570801