![]() |
|
#1
|
|||
|
|||
|
Greetings, I was trying to save my documents if the document was not saved for more than five minutes. I went this far but it is not dynamic enough. How can this be modified to get the job done? Thanks in advance!! Code:
Function lastsavetime(de As Boolean)
Dim bb As String, curt As Date, curr, intt As Integer, inttt As Integer, last As Date
curt = Now()
intt = InStr(1, curt, ":")
curr = Mid(curt, intt + 1, 2)
last = ActiveDocument.BuiltInDocumentProperties("Last Save Time")
inttt = InStr(1, last, ":")
bb = Mid(ActiveDocument.BuiltInDocumentProperties("Last Save Time"), intt + 1, 2)
If CInt(bb) - CInt(curr) >= 5 Then
de = True
End If
End Function
|
|
#2
|
|||
|
|||
|
Code:
Sub SaveMe()
Application.DisplayAlerts = False
ActiveDocument.Save
Application.DisplayAlerts = True
Application.OnTime Now + TimeValue("00:05:00"), "SaveMe"
MsgBox "Saved"
End Sub
|
|
#3
|
||||
|
||||
|
See also Automatically save Word Documents and Excel Workbooks. You can set your own time span for the current document or all documents.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#4
|
|||
|
|||
|
Thank you both gmaxey and gmayor for your help.
|
|
#5
|
|||
|
|||
|
Would you be able to add a vba code that auto save in the second location every 1 hour. Basically creating backup.
Thank you for sharing the code. I really appreciate how this gets me a leap away from slaving to Microsoft Onedrive autosave |
|
#6
|
||||
|
||||
|
If you look in the link I posted, the save in two places function in conjunction with the autosave will allow you to do this.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#7
|
|||
|
|||
|
You could use the following code:
Code:
Sub ActiveDocument_Save()
Application.OnTime Now + TimeValue("00:05:00"), "Savedoc"
Application.OnTime Now + TimeValue("01:00:00"), "Backupfile"
End Sub
Sub Savedoc()
ActiveDocument.Save
Application.OnTime Now + TimeValue("00:05:00"), "Savedoc"
End Sub
Sub Backupfile()
Dim str, name As String
With ActiveDocument
str = ActiveDocument.FullName
name = ActiveDocument.name
.Bookmarks.Add "CursorPosition", Selection.Range
.Save
.Close
FileCopy str, "D:\Your Desired Location\" & name
Application.OnTime Now + TimeValue("01:00:00"), "Backupfile"
Documents.Open str
ActiveDocument.Bookmarks("CursorPosition").Select
End With
End Sub
Code:
Sub SaveACopyToFlash()
Dim strFileA As String
Dim strFlash As String
strFlash = "D"
If strFlash = "" Then
MsgBox "User Cancelled", vbExclamation, "Cancelled"
Exit Sub
End If
With ActiveDocument
.Save 'save the original document
strFileA = .FullName 'Saved original document name
strFlash = strFlash & "\" & .name 'Flash drive filename
.Close 'Close the document
End With
On Error GoTo oops 'Error handler for missing flash drive
FileCopy strFileA, strFlash 'Copy source to flash
Documents.Open strFileA
ActiveWindow.View.Type = wdPrintView
End
oops:
If Err.Number = 61 Then
MsgBox "Disc Full! The partial file created will be deleted", vbExclamation
Kill strFlash 'Remove the partial file
Else
MsgBox "The flash drive is not available", vbExclamation
End If
Documents.Open strFileA
ActiveWindow.View.Type = wdPrintView
End Sub
|
|
#8
|
|||
|
|||
|
Thank you. This means a lot. I haven't seen this amount of Internet Magic for a while already!
I am so excited to get rid of Onedrive from my home device!!! |
|
| Tags |
| vba autosave document |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Viewable page automatically shifts after minutes
|
ZenHiker | Word | 1 | 10-22-2016 01:40 PM |
| Word is saving open document automatically in its own, | Jamal NUMAN | Word | 4 | 10-21-2016 01:37 PM |
Saving Attachment Automatically
|
emmanpelayo | Outlook | 5 | 09-28-2016 04:17 AM |
| Outlook is continuously & automatically opening (currently 8 screens in 10 minutes) | mikef | Outlook | 0 | 07-21-2014 01:49 PM |
| Word 2010 not saving automatically | darrylmarshall | Word | 1 | 06-07-2012 02:36 PM |