PDA

View Full Version : Set default suggested filename



vjdb
05-28-2008, 06:02 AM
I have used the solution provided by word mvps (
http://word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm)
but it does not do the trick. The default suggested filename only shows the first part of the title the part after the "-" is not suggested. Any ideas on how this is possible i use the following als string for the title:
Sub ChangeProps()
'change properties
If Documents.Count > 0 Then
Set dlgProp = Dialogs(wdDialogFileSummaryInfo)
' Establish title, subject, author, and keywords values
dlgProp.Title = MakeADocTitle(Date & ActiveDocument.Bookmarks("cool").Range.Text)
dlgProp.Subject = strTitle
dlgProp.Author = "Company Name"
dlgProp.Keywords = strKeywords I hope that somebody ahs a solution. TIA

fumei
05-28-2008, 02:23 PM
"the part after the "-" is not suggested."

I just made a document and put in a bookmark named "cool". Its Range.Text is " yadda".

MakeADocTitle(Date & ActiveDocument.Bookmarks("cool") _
.Range.Text)



produces:

2008-05-28 yadda

That is, it most certainly does have text after the "-".

Perhaps actually post your full code?

vjdb
05-29-2008, 12:22 AM
I used a extra bit of code. This is my full ocde:Sub ChangeProps()
'change properties
If Documents.Count > 0 Then
Set dlgProp = Dialogs(wdDialogFileSummaryInfo)
' Establish title, subject, author, and keywords values
dlgProp.Title = MakeADocTitle(Date & ActiveDocument.Bookmarks("cool").Range.Text)
dlgProp.Subject = strTitle
dlgProp.Author = "Company Name"
dlgProp.Keywords = strKeywords
' Set the values
dlgProp.Execute
' Show the dialog for testing purposes
dlgProp.Show
End If
End Sub
Function MakeADocTitle(ByVal strTitle As String) As String
arrSplit = Split(strTitle, " ")
MakeADocTitle = arrSplit(0)
For I = 1 To UBound(arrSplit)
MakeADocTitle = MakeADocTitle & Chr(95) & arrSplit(I)
Next I
MakeADocTitle = MakeADocTitle
End Function
Maybe this clears up things? What i want is to intercept the close command and then suggest a filename and a directory. The filename should look like this: 10-05-2008 - BookmarkSubject - BookmarkCompany - BookmarkThreatedBy. The "-" are causing the problems i think. Thank you for your efforts!

fumei
05-29-2008, 08:58 AM
10-05-2008 - BookmarkSubject - BookmarkCompany - BookmarkThreatedBy

Then you are stating that the text of the Bookmark "cool" is EXACTLY:

- BookmarkSubject - BookmarkCompany - BookmarkThreatedBy

including the space and the first "-"

Although....you do not state WHICH "-" is causing the problem. Hows about clearing that up.

vjdb
05-30-2008, 04:11 AM
The "- BookmarkSubject - BookmarkCompany - BookmarkThreatedBy" are just example input values for the filename. Let's suppose that i want to use only the bookmark "Cool" as a suggested filename. If the text in cool is "hello world". The suggested filename when i press "save as" or simply save (since it is a template im working with) the suggested filename is hello word.doc. But when bookamark cool contains hello-world then the suggested filename is only hello!

The problem is that the code does not support at all delimiters such as underscore (this occurs for example with the Date) the following website gives a workaround but that does not seem to work. It still only suggest the text before the underscore. That is even with the MakeADocTitle function inserted. This is website: http://word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm

Or should i do it differently and make a sub for the close document command? I have attached the template file to make sure we understand each other. Once again thanks!

fumei
05-30-2008, 01:31 PM
1. use Option Explicit in your code modules. You set it by checking Require Variable declaration under Tools > Options in the VBE. I strongly recommend you do this.

2. read the MVPS article again. It clearly states that delimiters will not work. It further clearly states you need to overwrite FileSaveAs to make it work the way you want.

Or, you can add an explicit procedure to do so. I have done this with your .dot file. There is now a "Use Title" on the top toolbar.

Click "Use Title". It displays the FileSaveAs dialog with the default name as "Date hello_world". I added Date back in.

BTW: I do not understand the purpose of showing the FileInfo dialog. Seems pointless to me, so I removed it.

Sub UseTitle()
Dim aDialog As Dialog
Set aDialog = Application.Dialogs(wdDialogFileSaveAs)

ActiveDocument.BuiltInDocumentProperties("Title") = _
MakeADocTitle(ActiveDocument.Bookmarks("cool").Range.Text)

With aDialog
.Name = Date & " " & _
ActiveDocument.BuiltInDocumentProperties("Title")
.Show
End With
End Sub