Sub GuardarArchivo()
'
' GuardarArchivo Macro
'
Dim rngFilename As Range
Dim strFileName As String
Set rngFilename = ActiveDocument.Range
With rngFilename
.End = .Start
.MoveEnd wdWord, 4
strFileName = .Text
End With
ActiveDocument.SaveAs "C:\Users\Alberto\Desktop\Pruebas\" & strFileName
End Sub
...
Dim blGuardar as Boolean
...
If Dir("C:\Users\Alberto\Desktop\Pruebas\" & strFileName) = "" Then 'El archivo no existe
blGuardar = True
Else
If MsgBox("El archivo ya existe. ¿Deseas reemplazarlo?", vbYesNo) = vbYes Then 'El archivo existe y deseamos reemplazarlo
blGuardar = True
Else
blGuardar = False
End If
End If
If blGuardar Then
ActiveDocument.SaveAs "C:\Users\Alberto\Desktop\Pruebas\" & strFileName
End If
...
Sub GuardarArchivo()
'
' GuardarArchivo Macro
'
Dim rngFilename As Range
Dim strFileName As String
Set rngFilename = ActiveDocument.Range
With rngFilename
.End = .Start
.MoveEnd wdWord, 4
strFileName = .Text
End With
' ---&--- Esta es la parte de código de Norberto
If Dir("C:\Users\Alberto\Desktop\Pruebas\" & strFileName) = "" Then 'El archivo no existe
blGuardar = True
Else
If MsgBox("El archivo ya existe. ¿Deseas reemplazarlo?", vbYesNo) = vbYes Then 'El archivo existe y deseamos reemplazarlo
blGuardar = True
Else
blGuardar = False
End If
End If
If blGuardar Then
ActiveDocument.SaveAs "C:\Users\Alberto\Desktop\Pruebas\" & strFileName
End If
End Sub
Sub GuardarArchivo()
'
' GuardarArchivo Macro
'
Dim rngFilename As Range
Dim strFileName As String
Set rngFilename = ActiveDocument.Range
With rngFilename
.End = .Start
.MoveEnd wdWord, 4
strFileName = .Text
End With
' ---&--- Esta lines es valida solo si ejecutas la macro con menos de 4 palabras en el primer párrafo.
If Asc(Right(strFileName, 1)) = 13 Then strFileName = Left(strFileName, Len(strFileName) - 1)
' ---&--- Aqui añado la extensión para verificar si existe
strFileName = strFileName + ".docx"
' ---&--- Esta es la parte de código de Norberto
If Dir("C:\Users\Alberto\Desktop\Pruebas\" & strFileName) = "" Then 'El archivo no existe
blGuardar = True
Else
If MsgBox("El archivo ya existe. ¿Deseas reemplazarlo?", vbYesNo) = vbYes Then 'El archivo existe y deseamos reemplazarlo
blGuardar = True
Else
blGuardar = False
End If
End If
If blGuardar Then
ActiveDocument.SaveAs "C:\Users\Alberto\Desktop\Pruebas\" & strFileName
End If
End Sub