I’ve got the following macro which is supposed to save a file as Citco, if the name already exist then its supposed to ask the user whether or not to overwrite, if the user clicks on yes it should overwrite else it should allow the user to enter a name and save it as that, else it should save it with am empty space as the name.
What it does is prompting the user that there is another file with the same name exist and even allows the user to enter another name but then it displays an error message saying that it cannot save.
I’m sure there are loads of error on this macro coz I combined two different macros to create this.
Would someone PLEASE me with this code?
Sub CitcoEx()
Dim strFileName As String
strFileName = “S:SRI_WORK_AREADOCUME~1” & “CitcoFax” & Format(Now, “DDMMYY”) & “.doc”
vResult = Dir(strFileName)
If vResult “” Then
vResult = MsgBox(“File ” & strFileName & _
” already exists, Would you like to overwrite that file?”, vbYesNo)
If vResult = vbYes Then
Application.DisplayAlerts = False
ActiveDocument.SaveAs FileName:=”S:SRI_WORK_AREADocuments” & strFileName, FileFormat:=wdFormatDocument
Application.DisplayAlerts = True
Else
strFileName = “S:SRI_WORK_AREADOCUME~1” _
& InputBox(“File ” & strFileName & ” already exists,” _
& Chr(10) & “Please enter another filename not including ” _
& Chr(34) & “.xls” & Chr(34) & “: “) & “.doc”
ActiveDocument.SaveAs FileName:=”S:SRI_WORK_AREADocuments” & strFileName, FileFormat:=wdFormatDocument
End If
‘Display message
Beep
MsgBox “File has been saved.”, vbInformation, “Export Confirmation”
Else
Application.DisplayAlerts = False
ActiveDocument.SaveAs FileName:=”S:SRI_WORK_AREADocuments” & strFileName, FileFormat:=wdFormatDocument
Application.DisplayAlerts = True
End If
End Sub