With macros that you can create in Word documents, you can let people fill in the forms you specify and have them saved automatically with some macro code. We show this in the Word Macro Command Button video.
----------
Code to rename and save your Word documents:
Dim strVer As String
Dim strDate As String
Dim strPath As String
Dim strFile As String
Dim oVars As Variables
Dim strFileType As WdDocumentType
Dim strVersionName As String
Dim intPos As Long
Dim sExt As String
Set oVars = ActiveDocument.Variables
strDate = Format ((Date), "dd MMM yyyy")
With ActiveDocument
On Error GoTo CanceledByUser
If Len (.Path) = 0 Then
'No path means document not saved
.Save 'So save it
End If
strPath = .Path 'Get path
strFile = .Name 'Get document name
End With
intPos = InStr (strFile, "-") 'Mark the version number
sExt = Right (strFile, Len (strFile) - InStrRev (strFile, & quot; .do & quot;))
If intPos = 0 Then
'No version number
intPos = InStrRev (strFile, ".do") 'Mark the extension instead
End If
strFile = Left (strFile, intPos - 1) 'Strip the extension or version number
Select Case LCase (sExt)
'Determine file type by extension
Case Is = "doc"
strFileType = 0
Case Is = "docx"
strFileType = 12
Case Is = "docm"
strFileType = 13
Case Is = "dot"
strFileType = 1
Case Is = "dotx"
strFileType = 14
Case Is = & quot; dotm & quot;
strFileType = 15
End Select
Start: 'Get Registry Data
On Error Resume Next 'No entry in registry will flag an error
strVer = oVars ("varVersion"). Value
If strVer = "" Then
'Variable does not exist
oVars ("VarVersion"). Value = "0" 'So create it
GoTo Start:
End If
On Error GoTo 0
strVer = Val (strVer) + 1 'Increment number
oVars ("varVersion"). Value = strVer
'Define the new version filename
strVersionName = strPath & "\" & strFile & "-" & strDate & _
"- Version" & Format (Val (strVer), "00 #") _
& Chr (46) & sExt
'and save a copy of the file with that name
ActiveDocument.SaveAs strVersionName, strFileType
ActiveDocument.Close
Exit Sub
CanceledByUser: 'Error handler
MsgBox "Canceled By User",, "Operation Canceled"
----------
FOLLOW US!
FACEBOOK - / ofislab
TWITTER - / ofislab