lupe_echave
12-01-2008, 11:53 PM
Hello,
This is the first time I post a message. I am a beginner in vba programming and I am having a problem with a procedure. I hope someone can help me, please.
Here is what I have:
This is my assignment:
Create a procedure that starts automatically when the user opens a document. Have this procedure:
1. Ask the user if they wish to automatically back-up this document
2. If the user selects yes, prompt them for the backup location (drive and folder)
3. Start a timed backup that will copy the document to the location selected by the user every 30 minutes
This is what I have:
Public Sub BackUp()
Dim msgPrompt As String, msgTitle As String
Dim msgButtons As Integer, msgResult As Integer
Dim backupFile As String
Dim currFile As String
Const BACKUP_FOLDER = "G:\Backup"
With ActiveDocument
msgPrompt = "Do you wish to automatically backup this document?"
msgButtons = vbYesNo + vbQuestion + vbDefaultButton2
msgTitle = "Automatically Backing Up"
msgResult = MsgBox(msgPrompt, msgButtons, msgTitle)
If msgResult = vbYes Then backupFile
' Don't bother if the document is unchanged or new
'
If .Saved Or .Path = "" Then Exit Sub
'
' Mark current position in document
'
.Bookmarks.Add Name:="LastPosition"
'
' Turn off screen updating
'
Application.ScreenUpdating = False
'
' Save the file
'
.Save
'
' Store the current file path, construct the path for
' the path for the backup file, and then save it to
' the backup folder
'
currFile = .FullName
backupFile = backup_file & .Name
.SaveAs FileName:=backupFile
End With
'
' Close the backup copy (which is now active)
'
ActiveDocument.Close
'
' Reopen the current file
'
Documents.Open FileName:=currFile
'
' Return to pre-backup position
'
Selection.GoTo what:=wdGoToBookmark, Name:="LastPosition"
'
' Turn screen updating back on
'
Application.ScreenUpdating = True
End Sub
End If
End Sub
:(
Can someone please HELP ME!
This is the first time I post a message. I am a beginner in vba programming and I am having a problem with a procedure. I hope someone can help me, please.
Here is what I have:
This is my assignment:
Create a procedure that starts automatically when the user opens a document. Have this procedure:
1. Ask the user if they wish to automatically back-up this document
2. If the user selects yes, prompt them for the backup location (drive and folder)
3. Start a timed backup that will copy the document to the location selected by the user every 30 minutes
This is what I have:
Public Sub BackUp()
Dim msgPrompt As String, msgTitle As String
Dim msgButtons As Integer, msgResult As Integer
Dim backupFile As String
Dim currFile As String
Const BACKUP_FOLDER = "G:\Backup"
With ActiveDocument
msgPrompt = "Do you wish to automatically backup this document?"
msgButtons = vbYesNo + vbQuestion + vbDefaultButton2
msgTitle = "Automatically Backing Up"
msgResult = MsgBox(msgPrompt, msgButtons, msgTitle)
If msgResult = vbYes Then backupFile
' Don't bother if the document is unchanged or new
'
If .Saved Or .Path = "" Then Exit Sub
'
' Mark current position in document
'
.Bookmarks.Add Name:="LastPosition"
'
' Turn off screen updating
'
Application.ScreenUpdating = False
'
' Save the file
'
.Save
'
' Store the current file path, construct the path for
' the path for the backup file, and then save it to
' the backup folder
'
currFile = .FullName
backupFile = backup_file & .Name
.SaveAs FileName:=backupFile
End With
'
' Close the backup copy (which is now active)
'
ActiveDocument.Close
'
' Reopen the current file
'
Documents.Open FileName:=currFile
'
' Return to pre-backup position
'
Selection.GoTo what:=wdGoToBookmark, Name:="LastPosition"
'
' Turn screen updating back on
'
Application.ScreenUpdating = True
End Sub
End If
End Sub
:(
Can someone please HELP ME!