Browse to a folder in VBA and save with file name pulled from document properties

sparrows

New Member
Joined
Jul 21, 2015
Messages
1
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
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top