I have two pieces of code one being a sub and the other is a function.
The sub asks the user for specific information using dialogue boxes(which open as soon as a new version of a template opens) and then enters that information throughout the document.
The function which I found on another thread supposedly open a dialogue box for the operator to save the file in any folder he chooses.
I would like to keep the original code as much as possible as this has been working with the company to an extent so far. I just require a dialogue box to open after the other dialogue boxes which selects which folder to save the document in.
In theory its so that nothing else in the document can be edited before the file has had the requested information added and is saved in a specified folder with a file name that has been pulled from the several parts of the information the user has already entered.
Quite hard to explain as you can understand from the above, but if anyone could decipher all of that and help me I would greatly appreciate it.
The code I have used is bellow:
Private Sub Document_New()
'
' AutoOpen Macro
'
Application.Run MacroName:="SaveWithName"
End Sub
________________________________________________________
Function GetFolder(strPath As String) As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
Set rngDoc = ActiveDocument.Content
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function
_____________________________________________________
Sub SaveWithName()
Dim strPath As String
Dim proDoc As DocumentProperty
Dim rngDoc As Range
ymd = Day(Now()) & "_" & Month(Now()) & "_" & Year(Now())
docnumber = InputBox("Enter Document Number", "docnumber")
ActiveDocument.BuiltInDocumentProperties("Subject").Value = docnumber
Title = InputBox("Enter Title", "Title")
ActiveDocument.BuiltInDocumentProperties("Title").Value = Title
Client = InputBox("Enter Client", "Client")
ActiveDocument.BuiltInDocumentProperties("Company").Value = Client
Site = InputBox("Enter Site", "Site")
ActiveDocument.BuiltInDocumentProperties("Category").Value = Site
Equip = InputBox("Enter Equipment Details", "Equip")
ActiveDocument.BuiltInDocumentProperties("Comments").Value = Equip
Rev = InputBox("Enter Rev", "Rev")
ActiveDocument.BuiltInDocumentProperties("Keywords").Value = Rev
Revstate = InputBox("Enter Revision Status", "Revstatus")
ActiveDocument.BuiltInDocumentProperties("Manager").Value = Revstate
FName = docnumber & "-" & Title & "-" & ymd & ".doc"
ActiveDocument.SaveAs FileName:=strPath & FName, FileFormat:=doc
End Sub
The sub asks the user for specific information using dialogue boxes(which open as soon as a new version of a template opens) and then enters that information throughout the document.
The function which I found on another thread supposedly open a dialogue box for the operator to save the file in any folder he chooses.
I would like to keep the original code as much as possible as this has been working with the company to an extent so far. I just require a dialogue box to open after the other dialogue boxes which selects which folder to save the document in.
In theory its so that nothing else in the document can be edited before the file has had the requested information added and is saved in a specified folder with a file name that has been pulled from the several parts of the information the user has already entered.
Quite hard to explain as you can understand from the above, but if anyone could decipher all of that and help me I would greatly appreciate it.
The code I have used is bellow:
Private Sub Document_New()
'
' AutoOpen Macro
'
Application.Run MacroName:="SaveWithName"
End Sub
________________________________________________________
Function GetFolder(strPath As String) As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
Set rngDoc = ActiveDocument.Content
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function
_____________________________________________________
Sub SaveWithName()
Dim strPath As String
Dim proDoc As DocumentProperty
Dim rngDoc As Range
ymd = Day(Now()) & "_" & Month(Now()) & "_" & Year(Now())
docnumber = InputBox("Enter Document Number", "docnumber")
ActiveDocument.BuiltInDocumentProperties("Subject").Value = docnumber
Title = InputBox("Enter Title", "Title")
ActiveDocument.BuiltInDocumentProperties("Title").Value = Title
Client = InputBox("Enter Client", "Client")
ActiveDocument.BuiltInDocumentProperties("Company").Value = Client
Site = InputBox("Enter Site", "Site")
ActiveDocument.BuiltInDocumentProperties("Category").Value = Site
Equip = InputBox("Enter Equipment Details", "Equip")
ActiveDocument.BuiltInDocumentProperties("Comments").Value = Equip
Rev = InputBox("Enter Rev", "Rev")
ActiveDocument.BuiltInDocumentProperties("Keywords").Value = Rev
Revstate = InputBox("Enter Revision Status", "Revstatus")
ActiveDocument.BuiltInDocumentProperties("Manager").Value = Revstate
FName = docnumber & "-" & Title & "-" & ymd & ".doc"
ActiveDocument.SaveAs FileName:=strPath & FName, FileFormat:=doc
End Sub