Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically Naming a document
I posted this on another group and did not get a response so I'll try
here. I have a Word form with several fields one of which is a date field. I would like the date entered in the date field to show as the name of the form when the form is emailed as an attachment and/or saved. How is this accomplished? Thanks in advance Ron |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically Naming a document
On Mon, 23 Jun 2008 16:05:11 -0700 (PDT), A_Classic_Man
wrote: I posted this on another group and did not get a response so I'll try here. I have a Word form with several fields one of which is a date field. I would like the date entered in the date field to show as the name of the form when the form is emailed as an attachment and/or saved. How is this accomplished? Thanks in advance Ron For the Save part, see http://www.word.mvps.org/FAQs/Macros...efFilename.htm. I don't know whether that will suffice for the email attachment or whether you'll need a separate macro for that. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Automatically Naming a document
The big problem you are likely to encounter, whether you use a macro or the
method Jay pointed to is the question of reserved characters that are likely to form part of the date. For example you would not be able to save a document with the name 24/6/2008 - though 24 June 2008 would work. With this proviso, assuming the field with the date is bookmarked Text1 - the following macro run on entry to the next form field will initially save the document with the name as the content of Text1 Sub Save_As_Date() Dim oFld As FormFields Dim sFname As String Set oFld = ActiveDocument.FormFields sFname = oFld("Text1").Result MsgBox sFname ActiveDocument.SaveAs sFname End Sub This will raise another issue relating to the use of macros at a remote site, where you have no way of forcing the user to run macros contained in a document. If you are going the whole hog and distributing a template then you could add a button to send the document to you. The following macro uses Outlook to send the document as attachment to the address entered having saved the document with the required filename (subject to the same provisos as above - plus the user has to be using Outlook) Sub SendDocumentAsAttachment() Dim bStarted As Boolean Dim oFld As FormFields Dim sFname As String Set oFld = ActiveDocument.FormFields Dim oOutlookApp As Outlook.Application Dim oItem As Outlook.MailItem On Error Resume Next If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved 'Save the document sFname = oFld("Text1").Result ActiveDocument.SaveAs sFname End If 'see if Outlook is running and if so turn your attention there Set oOutlookApp = GetObject(, "Outlook.Application") If Err 0 Then 'Outlook isn't running 'So fire it up Set oOutlookApp = CreateObject("Outlook.Application") bStarted = True End If 'Open a new e-mail message Set oItem = oOutlookApp.CreateItem(olMailItem) With oItem 'and add the detail to it .To = " 'send to this address .Subject = ActiveDocument.name 'This is the message subject .Body = "See attached document" ' This is the message body text .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue .Send '********************************** 'If you want to view the message before it goes 'change the line above from .Send to .Display 'Otherwise the message is sent straight to the Outbox 'and if you have Outlook set to send mail immediately, 'it will simply be Sent 'with no obvious sign that Outlook has operated. 'Apart from the copy in the Outlook Sent folder '********************************** End With If bStarted Then 'If the macro started Outlook, stop it again. oOutlookApp.Quit End If 'Clean up Set oItem = Nothing Set oOutlookApp = Nothing End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org A_Classic_Man wrote: I posted this on another group and did not get a response so I'll try here. I have a Word form with several fields one of which is a date field. I would like the date entered in the date field to show as the name of the form when the form is emailed as an attachment and/or saved. How is this accomplished? Thanks in advance Ron |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
files organization and naming | Microsoft Word Help | |||
Document Naming Conventions for Standard Operating Procedures/Configuration Managment | Microsoft Word Help | |||
Automatically naming documents with data in form fields? | Microsoft Word Help | |||
file naming | Microsoft Word Help | |||
Naming a cell | Tables |