Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Need answer quick
I know I already asked this question but I wasn't able to post the code until
now. I have been trying to make a template for my company (vet hospital) for our surgery dismissals. I'm totally new to this and have been having many many problems. After finally figuring out how to do the userform I tested it. When I hit the OK or Cancel buttons the template disappears and Word goes into a regular blank document. Here's the code for the userform and the OK and Cancel buttons. This is for the Userform: Private Sub Document_New() Dim oForm As frmDismissal On Error Goto Error_DocumentNew Set oForm = New frmDismissal oForm.Tag = "Cancel" oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy") oForm.Show If oForm.Tag = "OK" Then ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text Unload oForm Set oForm = Nothing Else Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges End If Exit_DocumentNew: Exit Sub Error_DocumentNew: On Error Resume Next Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges Resume Exit_DocumentNew End Sub Here's the next one (for the cancel button): Option Explicit Private Sub cmdCancel_Click() Me.Hide End Sub Here's the ok button: Private Sub cmdOK_Click() Me.Tag = "OK" Me.Hide End Sub Just one last thing....is there a way for me to have the bookmark be a certain name (i.e. ClientName) instead of just a blank space with the bookmark icon? Thanks for all your help!! Jill |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Need answer quick
There are multiple problems in your post, so let me try to answer them one
at a time. - First, I hope you aren't trying to test the userform directly in the template itself, and that instead you're using the File New dialog to create a new document based on the template. The Document_New procedure runs automatically when the new document is created. - In the template (and thus inherited by new documents based on the template), you must start with at least the four bookmarks named by the macro. The capitalization of the names is not important, but the spelling must be exactly the same in the Insert Bookmark dialog as it is in the macro. If any one of the bookmarks doesn't exist in the document, the On Error statement will cause the macro to go to the Error_DocumentNew label, where the document will be closed without saving. This is most probably what's happening to you. (There's another location where the document closes, but that should happen only when you click Cancel in the userform.) - If the bookmarks aren't the problem, temporarily comment out all the On Error statements (put an apostrophe at the beginning of the line), run the macro, and see what line is highlighted when an error stops the macro. Post that line and the exact text of the error message here as a reply (PLEASE don't start yet another thread!). - Bookmarks don't have "icons". If you have the Bookmarks option checked in Tools Options View, a bookmark that encloses one or more characters looks like a pair of bold gray square brackets [ ] or a bookmark that encloses nothing looks like an I-beam because the vertical lines overlap. A bookmark may enclose spaces, words, pictures, or pretty much anything you want -- just select the text or object before using Insert Bookmark. When your userform finally works, the text or object enclosed by the bookmark will be replaced by the text from the userform *and the bookmark itself will be deleted* -- http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm explains how to restore the bookmark if needed. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Jill D wrote: I know I already asked this question but I wasn't able to post the code until now. I have been trying to make a template for my company (vet hospital) for our surgery dismissals. I'm totally new to this and have been having many many problems. After finally figuring out how to do the userform I tested it. When I hit the OK or Cancel buttons the template disappears and Word goes into a regular blank document. Here's the code for the userform and the OK and Cancel buttons. This is for the Userform: Private Sub Document_New() Dim oForm As frmDismissal On Error Goto Error_DocumentNew Set oForm = New frmDismissal oForm.Tag = "Cancel" oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy") oForm.Show If oForm.Tag = "OK" Then ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text Unload oForm Set oForm = Nothing Else Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges End If Exit_DocumentNew: Exit Sub Error_DocumentNew: On Error Resume Next Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges Resume Exit_DocumentNew End Sub Here's the next one (for the cancel button): Option Explicit Private Sub cmdCancel_Click() Me.Hide End Sub Here's the ok button: Private Sub cmdOK_Click() Me.Tag = "OK" Me.Hide End Sub Just one last thing....is there a way for me to have the bookmark be a certain name (i.e. ClientName) instead of just a blank space with the bookmark icon? Thanks for all your help!! Jill |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Need answer quick
Sorry about all the threads!!
Thank you for the advice. I really appreciate all your help that you're giving me. I apologize that I am such a novice at this. The whole UserForm, template and code stuff is all new to me (especially the codes!) I had a question about your first statement. I'm not sure what you mean by testing the userform directly in the template. I don't know how to create a new document based on the template without opening the template first. I got two completely different ways to create a userform from websites and to tell you the truth I wouldn't know which one is actually the correct way. One was from the MVP site and the other was from dragondrop. Once again your help is greatly appreciated!!! Jill "Jay Freedman" wrote: There are multiple problems in your post, so let me try to answer them one at a time. - First, I hope you aren't trying to test the userform directly in the template itself, and that instead you're using the File New dialog to create a new document based on the template. The Document_New procedure runs automatically when the new document is created. - In the template (and thus inherited by new documents based on the template), you must start with at least the four bookmarks named by the macro. The capitalization of the names is not important, but the spelling must be exactly the same in the Insert Bookmark dialog as it is in the macro. If any one of the bookmarks doesn't exist in the document, the On Error statement will cause the macro to go to the Error_DocumentNew label, where the document will be closed without saving. This is most probably what's happening to you. (There's another location where the document closes, but that should happen only when you click Cancel in the userform.) - If the bookmarks aren't the problem, temporarily comment out all the On Error statements (put an apostrophe at the beginning of the line), run the macro, and see what line is highlighted when an error stops the macro. Post that line and the exact text of the error message here as a reply (PLEASE don't start yet another thread!). - Bookmarks don't have "icons". If you have the Bookmarks option checked in Tools Options View, a bookmark that encloses one or more characters looks like a pair of bold gray square brackets [ ] or a bookmark that encloses nothing looks like an I-beam because the vertical lines overlap. A bookmark may enclose spaces, words, pictures, or pretty much anything you want -- just select the text or object before using Insert Bookmark. When your userform finally works, the text or object enclosed by the bookmark will be replaced by the text from the userform *and the bookmark itself will be deleted* -- http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm explains how to restore the bookmark if needed. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Jill D wrote: I know I already asked this question but I wasn't able to post the code until now. I have been trying to make a template for my company (vet hospital) for our surgery dismissals. I'm totally new to this and have been having many many problems. After finally figuring out how to do the userform I tested it. When I hit the OK or Cancel buttons the template disappears and Word goes into a regular blank document. Here's the code for the userform and the OK and Cancel buttons. This is for the Userform: Private Sub Document_New() Dim oForm As frmDismissal On Error Goto Error_DocumentNew Set oForm = New frmDismissal oForm.Tag = "Cancel" oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy") oForm.Show If oForm.Tag = "OK" Then ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text Unload oForm Set oForm = Nothing Else Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges End If Exit_DocumentNew: Exit Sub Error_DocumentNew: On Error Resume Next Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges Resume Exit_DocumentNew End Sub Here's the next one (for the cancel button): Option Explicit Private Sub cmdCancel_Click() Me.Hide End Sub Here's the ok button: Private Sub cmdOK_Click() Me.Tag = "OK" Me.Hide End Sub Just one last thing....is there a way for me to have the bookmark be a certain name (i.e. ClientName) instead of just a blank space with the bookmark icon? Thanks for all your help!! Jill |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Need answer quick
Hi, I was wondering if you were still going to help me??? I haven't heard
back from you yet and I still need help!! Thanks "Jill D" wrote: Sorry about all the threads!! Thank you for the advice. I really appreciate all your help that you're giving me. I apologize that I am such a novice at this. The whole UserForm, template and code stuff is all new to me (especially the codes!) I had a question about your first statement. I'm not sure what you mean by testing the userform directly in the template. I don't know how to create a new document based on the template without opening the template first. I got two completely different ways to create a userform from websites and to tell you the truth I wouldn't know which one is actually the correct way. One was from the MVP site and the other was from dragondrop. Once again your help is greatly appreciated!!! Jill "Jay Freedman" wrote: There are multiple problems in your post, so let me try to answer them one at a time. - First, I hope you aren't trying to test the userform directly in the template itself, and that instead you're using the File New dialog to create a new document based on the template. The Document_New procedure runs automatically when the new document is created. - In the template (and thus inherited by new documents based on the template), you must start with at least the four bookmarks named by the macro. The capitalization of the names is not important, but the spelling must be exactly the same in the Insert Bookmark dialog as it is in the macro. If any one of the bookmarks doesn't exist in the document, the On Error statement will cause the macro to go to the Error_DocumentNew label, where the document will be closed without saving. This is most probably what's happening to you. (There's another location where the document closes, but that should happen only when you click Cancel in the userform.) - If the bookmarks aren't the problem, temporarily comment out all the On Error statements (put an apostrophe at the beginning of the line), run the macro, and see what line is highlighted when an error stops the macro. Post that line and the exact text of the error message here as a reply (PLEASE don't start yet another thread!). - Bookmarks don't have "icons". If you have the Bookmarks option checked in Tools Options View, a bookmark that encloses one or more characters looks like a pair of bold gray square brackets [ ] or a bookmark that encloses nothing looks like an I-beam because the vertical lines overlap. A bookmark may enclose spaces, words, pictures, or pretty much anything you want -- just select the text or object before using Insert Bookmark. When your userform finally works, the text or object enclosed by the bookmark will be replaced by the text from the userform *and the bookmark itself will be deleted* -- http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm explains how to restore the bookmark if needed. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Jill D wrote: I know I already asked this question but I wasn't able to post the code until now. I have been trying to make a template for my company (vet hospital) for our surgery dismissals. I'm totally new to this and have been having many many problems. After finally figuring out how to do the userform I tested it. When I hit the OK or Cancel buttons the template disappears and Word goes into a regular blank document. Here's the code for the userform and the OK and Cancel buttons. This is for the Userform: Private Sub Document_New() Dim oForm As frmDismissal On Error Goto Error_DocumentNew Set oForm = New frmDismissal oForm.Tag = "Cancel" oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy") oForm.Show If oForm.Tag = "OK" Then ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text Unload oForm Set oForm = Nothing Else Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges End If Exit_DocumentNew: Exit Sub Error_DocumentNew: On Error Resume Next Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges Resume Exit_DocumentNew End Sub Here's the next one (for the cancel button): Option Explicit Private Sub cmdCancel_Click() Me.Hide End Sub Here's the ok button: Private Sub cmdOK_Click() Me.Tag = "OK" Me.Hide End Sub Just one last thing....is there a way for me to have the bookmark be a certain name (i.e. ClientName) instead of just a blank space with the bookmark icon? Thanks for all your help!! Jill |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Need answer quick
From the File menu, select New and then select the template that you have
created. A new document will be created based on that template and if you have the commands in the AutoNew macro correct, the userform will then be shown. -- 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 "Jill D" wrote in message ... Sorry about all the threads!! Thank you for the advice. I really appreciate all your help that you're giving me. I apologize that I am such a novice at this. The whole UserForm, template and code stuff is all new to me (especially the codes!) I had a question about your first statement. I'm not sure what you mean by testing the userform directly in the template. I don't know how to create a new document based on the template without opening the template first. I got two completely different ways to create a userform from websites and to tell you the truth I wouldn't know which one is actually the correct way. One was from the MVP site and the other was from dragondrop. Once again your help is greatly appreciated!!! Jill "Jay Freedman" wrote: There are multiple problems in your post, so let me try to answer them one at a time. - First, I hope you aren't trying to test the userform directly in the template itself, and that instead you're using the File New dialog to create a new document based on the template. The Document_New procedure runs automatically when the new document is created. - In the template (and thus inherited by new documents based on the template), you must start with at least the four bookmarks named by the macro. The capitalization of the names is not important, but the spelling must be exactly the same in the Insert Bookmark dialog as it is in the macro. If any one of the bookmarks doesn't exist in the document, the On Error statement will cause the macro to go to the Error_DocumentNew label, where the document will be closed without saving. This is most probably what's happening to you. (There's another location where the document closes, but that should happen only when you click Cancel in the userform.) - If the bookmarks aren't the problem, temporarily comment out all the On Error statements (put an apostrophe at the beginning of the line), run the macro, and see what line is highlighted when an error stops the macro. Post that line and the exact text of the error message here as a reply (PLEASE don't start yet another thread!). - Bookmarks don't have "icons". If you have the Bookmarks option checked in Tools Options View, a bookmark that encloses one or more characters looks like a pair of bold gray square brackets [ ] or a bookmark that encloses nothing looks like an I-beam because the vertical lines overlap. A bookmark may enclose spaces, words, pictures, or pretty much anything you want -- just select the text or object before using Insert Bookmark. When your userform finally works, the text or object enclosed by the bookmark will be replaced by the text from the userform *and the bookmark itself will be deleted* -- http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm explains how to restore the bookmark if needed. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Jill D wrote: I know I already asked this question but I wasn't able to post the code until now. I have been trying to make a template for my company (vet hospital) for our surgery dismissals. I'm totally new to this and have been having many many problems. After finally figuring out how to do the userform I tested it. When I hit the OK or Cancel buttons the template disappears and Word goes into a regular blank document. Here's the code for the userform and the OK and Cancel buttons. This is for the Userform: Private Sub Document_New() Dim oForm As frmDismissal On Error Goto Error_DocumentNew Set oForm = New frmDismissal oForm.Tag = "Cancel" oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy") oForm.Show If oForm.Tag = "OK" Then ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text Unload oForm Set oForm = Nothing Else Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges End If Exit_DocumentNew: Exit Sub Error_DocumentNew: On Error Resume Next Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges Resume Exit_DocumentNew End Sub Here's the next one (for the cancel button): Option Explicit Private Sub cmdCancel_Click() Me.Hide End Sub Here's the ok button: Private Sub cmdOK_Click() Me.Tag = "OK" Me.Hide End Sub Just one last thing....is there a way for me to have the bookmark be a certain name (i.e. ClientName) instead of just a blank space with the bookmark icon? Thanks for all your help!! Jill |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Need answer quick
Hi, sorry I missed your post.
As Doug says, you need to use the New command on the File menu and choose your template in the dialog. If you're using Word 2002 or 2003, they've made this needlessly complicated -- when you click File New you get a task pane, and you then have to click the link for "On my computer" to get the dialog where you can choose the template. The two ways of creating a userform aren't really that different. You can use either one while you get more familiar with the whole process. The method at dragondrop.com is technically more correct, but it is more complicated, and it matters only if you're making a template with more than one userform. -- 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. On Sat, 19 Nov 2005 21:35:01 -0800, Jill D wrote: Hi, I was wondering if you were still going to help me??? I haven't heard back from you yet and I still need help!! Thanks "Jill D" wrote: Sorry about all the threads!! Thank you for the advice. I really appreciate all your help that you're giving me. I apologize that I am such a novice at this. The whole UserForm, template and code stuff is all new to me (especially the codes!) I had a question about your first statement. I'm not sure what you mean by testing the userform directly in the template. I don't know how to create a new document based on the template without opening the template first. I got two completely different ways to create a userform from websites and to tell you the truth I wouldn't know which one is actually the correct way. One was from the MVP site and the other was from dragondrop. Once again your help is greatly appreciated!!! Jill "Jay Freedman" wrote: There are multiple problems in your post, so let me try to answer them one at a time. - First, I hope you aren't trying to test the userform directly in the template itself, and that instead you're using the File New dialog to create a new document based on the template. The Document_New procedure runs automatically when the new document is created. - In the template (and thus inherited by new documents based on the template), you must start with at least the four bookmarks named by the macro. The capitalization of the names is not important, but the spelling must be exactly the same in the Insert Bookmark dialog as it is in the macro. If any one of the bookmarks doesn't exist in the document, the On Error statement will cause the macro to go to the Error_DocumentNew label, where the document will be closed without saving. This is most probably what's happening to you. (There's another location where the document closes, but that should happen only when you click Cancel in the userform.) - If the bookmarks aren't the problem, temporarily comment out all the On Error statements (put an apostrophe at the beginning of the line), run the macro, and see what line is highlighted when an error stops the macro. Post that line and the exact text of the error message here as a reply (PLEASE don't start yet another thread!). - Bookmarks don't have "icons". If you have the Bookmarks option checked in Tools Options View, a bookmark that encloses one or more characters looks like a pair of bold gray square brackets [ ] or a bookmark that encloses nothing looks like an I-beam because the vertical lines overlap. A bookmark may enclose spaces, words, pictures, or pretty much anything you want -- just select the text or object before using Insert Bookmark. When your userform finally works, the text or object enclosed by the bookmark will be replaced by the text from the userform *and the bookmark itself will be deleted* -- http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm explains how to restore the bookmark if needed. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Jill D wrote: I know I already asked this question but I wasn't able to post the code until now. I have been trying to make a template for my company (vet hospital) for our surgery dismissals. I'm totally new to this and have been having many many problems. After finally figuring out how to do the userform I tested it. When I hit the OK or Cancel buttons the template disappears and Word goes into a regular blank document. Here's the code for the userform and the OK and Cancel buttons. This is for the Userform: Private Sub Document_New() Dim oForm As frmDismissal On Error Goto Error_DocumentNew Set oForm = New frmDismissal oForm.Tag = "Cancel" oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy") oForm.Show If oForm.Tag = "OK" Then ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text Unload oForm Set oForm = Nothing Else Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges End If Exit_DocumentNew: Exit Sub Error_DocumentNew: On Error Resume Next Unload oForm Set oForm = Nothing ActiveDocument.Close wdDoNotSaveChanges Resume Exit_DocumentNew End Sub Here's the next one (for the cancel button): Option Explicit Private Sub cmdCancel_Click() Me.Hide End Sub Here's the ok button: Private Sub cmdOK_Click() Me.Tag = "OK" Me.Hide End Sub Just one last thing....is there a way for me to have the bookmark be a certain name (i.e. ClientName) instead of just a blank space with the bookmark icon? Thanks for all your help!! Jill |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Adding fields based on yes/no answer in a form | Tables | |||
Make styles available in ALL documents? HELP Answer doesn't work | Microsoft Word Help | |||
word help doesn't work but the wizerd does answer my questions. | Microsoft Word Help | |||
set up form fields with answer, then certain response appears | New Users | |||
I don't get the (Conents, Answer Wizard, Index) tab? | Microsoft Word Help |