Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Set the filename for a document created from a template

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don Wilkinson - 28 Apr 2006 19:42 GMT
I'm new to macros and the like, so please be gentle to me and explicit with
me. :)

I have a Word template that is a form my users will fill out.  I am planning
to have them send the complete form to me in email.  

This form contains a text field box with the bookmark name "EmpName".

When they click on the shortcut to my template, they of course get a new
Word doc based on the template, with the temporary document name "document#".
If they then use File --> Send To --> Email Recipient (As Attachment)
feature, the file attachment is named "document#".  

I want a way to grab the data from the EmpName field and use that to
generate the filename given when the document is attached.  For example "User
Setup - EmpName".

I understand I may need to have the user press a key or Save the document
first.

I imagine I will need a bit of info about the Properties of the Text field
so that it "calculates on exit" or whatever.  But, I KNOW I'll need the
script bits to do the filename updating, etc.  

I really hope you can help me, of course, but I'm also excited that I will
learn something too!

Thanks in advance,
Don
td - 30 Apr 2006 09:28 GMT
Hello Don
I will leave the experts to answer your question but: Why use EmpName? Why
not use the user's Windows logon name? Using the logon name means the user
does not have to type./select anything.
Cheers
td

> I'm new to macros and the like, so please be gentle to me and explicit with
> me. :)
[quoted text clipped - 25 lines]
> Thanks in advance,
> Don
Don Wilkinson - 02 May 2006 18:21 GMT
TD,
the "EmpName" field refers to a thrid party, not the current user.

Thanks,
Don

> Hello Don
> I will leave the experts to answer your question but: Why use EmpName? Why
[quoted text clipped - 32 lines]
> > Thanks in advance,
> > Don
Doug Robbins - Word MVP - 30 Apr 2006 10:54 GMT
Use the following code in a macro that is run on exit from the "EmpName"
form field

ActiveDocument.SaveAs ActiveDocument.Bookmarks("EmpName").Result & " -
completed form"

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> I'm new to macros and the like, so please be gentle to me and explicit
> with
[quoted text clipped - 29 lines]
> Thanks in advance,
> Don
Don Wilkinson - 02 May 2006 18:22 GMT
Doug,
thank you.  I will go and try it.  Assuming I can figure out the basics of
using code from Word form...  That's my homework.  

I actually expect myself to learn some things on my own.  Not to have
everything handed to me. ;-)

Don

> Use the following code in a macro that is run on exit from the "EmpName"
> form field
[quoted text clipped - 35 lines]
> > Thanks in advance,
> > Don
Don Wilkinson - 02 May 2006 19:04 GMT
Hello Doug,

I created a macro in my form template.  I tested the new form and when I
enter data into the EmpName field and move to the next field (exit) I get
this error:

"Compile Error: Method or Data member not found."

and the ".Result" part of the macro code is highlighted in the VB debug
window.  This is Word 2003SP2, btw.  I don't have a reference to supported
methods; is .Results "good"?  :)

Here is my code block for the macro in TemplateProject-Modules-Module1:

   Sub SaveFormWithName()
       ActiveDocument.SaveAs ActiveDocument.Bookmarks("EmpName").Result & "
-     completed form"
   End Sub

Note:  when I pasted your code sample, I added indent.  Also, the editor
wordwrapped the string and added an extra doublequote to the end of the line,
which looked to me like it would break the string.  So, I 'corrected' it to
what you see above.

If I get it working, I'll probably recode a bit more to something like;

   Sub SaveFormWithName()
       ActiveDocument.SaveAs & "UserSetupRequest-"
ActiveDocument.Bookmarks("EmpName").Result
   End Sub

> Use the following code in a macro that is run on exit from the "EmpName"
> form field
[quoted text clipped - 35 lines]
> > Thanks in advance,
> > Don
Don Wilkinson - 02 May 2006 23:16 GMT
Hello again, Doug,

I very much appreciate your time.  Having been in you position many times, I
know that it's often diffcult, and rarely attempted, to help someone with
their script problems.  It's often something as simple but as elusive as a
misplaced space character and the like.  :)

In this case, I think that my post may have workwrapped in such a way as to
mislead you you as to the cause of the error I reported or something.  I
don't think I am having a syntax problem due to not using the proper
'continued on next line' character or the like.  

As I specifically showed before, the debugger is complaining about the
*method* and it's highlighting ".Result".  

I reemphasize this because my script was all on one line - linewrapping does
not seem a likely cause to my problem.  Furthermore, I've tried changing the
code to match what you gave me in format and got the same error.
 
Finally, I changed the code to:

   Sub SaveFormWithName()
       ActiveDocument.SaveAs ActiveDocument.Bookmarks("EmpName").Result
  End Sub

And got the SAME error.  Next idea?  :)

Thanks,
Don

> Hello Doug,
>
[quoted text clipped - 66 lines]
> > > Thanks in advance,
> > > Don
Doug Robbins - Word MVP - 04 May 2006 21:11 GMT
Hi Don,

Sorry the problem is an error in the code that I gave you.  It should have
been:

ActiveDocument.SaveAs ActiveDocument.FormFields("EmpName").Result etc.

The .Result is a property of a FormField, not a bookmark
Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hello again, Doug,
>
[quoted text clipped - 112 lines]
>> > > Thanks in advance,
>> > > Don
Doug Robbins - Word MVP - 02 May 2006 22:17 GMT
The
       ActiveDocument.SaveAs ActiveDocument.Bookmarks("EmpName").Result & "
-     completed form"
needs to be all on one line or have a Visual Basic line break character
inserted like

      ActiveDocument.SaveAs ActiveDocument.Bookmarks("EmpName").Result & _
" - completed form"

Note that there is a space between the ampersand and the underscore
character.
Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Use the following code in a macro that is run on exit from the "EmpName"
> form field
[quoted text clipped - 37 lines]
>> Thanks in advance,
>> Don
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.