SALVAR COM COMONDIALOG
Bom dia,
Estou usando o codigo abaixo para salvar arquivos em uma pasta usando o commondialog. O que preciso acrescentar para que se o nome escolhido pelo usuario já existir na pasta, aparecer aquela mensagem "O arquivo já existe. Deseja substitui-lo?". Obrigado.
Dim Diretorio As String
On Error GoTo Err
Diretorio = CommonDialog1.FileName
CommonDialog1.DialogTitle = "Salvar Nota"
CommonDialog1.Filter = "Arquivos de Texto (*.rtf)|*.rtf"
If Not Diretorio = Empty Then
CommonDialog1.InitDir = Diretorio
Else
CommonDialog1.InitDir = App.Path & "\Notas"
End If
If Right$(CommonDialog1.InitDir, 1) <> "\" Then CommonDialog1.InitDir = CommonDialog1.InitDir & "\"
CommonDialog1.FileName = Empty
CommonDialog1.ShowSave
If Not CommonDialog1.FileName = Empty Then
RichTextBox1.SaveFile CommonDialog1.FileName, 0
End If
Exit Sub
Err:
If Err.Number = 32755 Then
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description & ".", vbCritical, "Erro"
End If
Estou usando o codigo abaixo para salvar arquivos em uma pasta usando o commondialog. O que preciso acrescentar para que se o nome escolhido pelo usuario já existir na pasta, aparecer aquela mensagem "O arquivo já existe. Deseja substitui-lo?". Obrigado.
Dim Diretorio As String
On Error GoTo Err
Diretorio = CommonDialog1.FileName
CommonDialog1.DialogTitle = "Salvar Nota"
CommonDialog1.Filter = "Arquivos de Texto (*.rtf)|*.rtf"
If Not Diretorio = Empty Then
CommonDialog1.InitDir = Diretorio
Else
CommonDialog1.InitDir = App.Path & "\Notas"
End If
If Right$(CommonDialog1.InitDir, 1) <> "\" Then CommonDialog1.InitDir = CommonDialog1.InitDir & "\"
CommonDialog1.FileName = Empty
CommonDialog1.ShowSave
If Not CommonDialog1.FileName = Empty Then
RichTextBox1.SaveFile CommonDialog1.FileName, 0
End If
Exit Sub
Err:
If Err.Number = 32755 Then
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description & ".", vbCritical, "Erro"
End If
Cara tenta isso:
'(GENERAL)
Dim response As Integer
'(Command_salvar)
Private Sub Command1_Click()
CommonDialog1.ShowSave
If Dir$(CommonDialog1.FileName) <> "" Then
response = MsgBox("O arquivo ja existe. Você deseja salvar em cima?", vbYesNo, "Arquivo Existe!")
If response = vbYes Then
'==FUNÇÃO PRA GRAVAR===
End If
If response = vbNo Then
'===FAZ O QUE VOCÃÅ QUISER====
End If
Else
MsgBox "O arquivo NÃO existe"
'==FUNÇÃO PRA GRAVAR===
End If
End Sub
Grato novamente Gabriel.
Luiz
Luiz
Tópico encerrado , respostas não são mais permitidas