Thread: [Solved] Save in two places
View Single Post
 
Old 01-21-2016, 07:04 AM
menteith menteith is offline Windows 7 32bit Office 2016
Novice
 
Join Date: Jan 2016
Posts: 3
menteith is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
If nothing there suits your needs, you might try something along the lines of:
Thank you very much for this. Your solution is simple (and it should be!) and does the trick. There is one thing I would like to have and I cannot achieve on my own.


1. If I open Word (no document opened, just blank page), modify it and choose to close Word, a SaveAs dialog is shown. Is there a chance to show an ordinary Word dialogue asking a question whether a document should be saved or not ot, or to cancel? Currently, in the above-mentioned situation, there is no chance of quitting Word without saving, that is, when I choose not to save, I get back to Word (it does not exit.)


I have also one comment.
If a document exists on, say, harddrive, pendrive etc. and I modify it and choose to save, there is a dialogue box asking whether to save or not. In this situation, saving without asking would be preferred for me. I have changed the macro accordingly. Please see it below.
Code:
Sub FileSave()
Dim BackupPath As String, objF As Object, retVal As Long, Rslt
BackupPath = "C:\Users\" & Environ("UserName") & "\Documents\BackupWord\"
With ActiveDocument
  If .Path = "" Then: If Application.Dialogs(wdDialogFileSaveAs).Show <> -1 Then Exit Sub
  If .Saved = False Then .Save
  If Dir(BackupPath, vbDirectory) = "" Then
    MkDir BackupPath
    MsgBox "Backup folder has been created.", vbInformation
  End If
  If .Path & "\" = BackupPath Then
    MsgBox "WARNING! Backup folder is the same as the source folder", vbExclamation
    Exit Sub
  End If
  Set objF = CreateObject("Scripting.FileSystemObject")
  retVal = -1
  On Error Resume Next
  retVal = objF.CopyFile(.FullName, BackupPath & .Name, True)
  On Error GoTo 0
  Set objF = Nothing
  If retVal <> 0 Then MsgBox "Backup has not been copied to folder " & BackupPath, vbExclamation
End With
End Sub

I have also changed your first macro to exit Word when I choose to do so and if a document is empty.
Code:
Private Sub Document_Close()
Dim blank As Range
For Each blank In ActiveDocument.StoryRanges
If Len(blank.Text) = 0 Then Exit Sub
Next
Call FileSave
SendKeys "{ESC}"
End Sub
Reply With Quote