I want to create a template document that when opened (or perhaps when
saved) prompts the user for some information and forms the document's
name out of that information filled into a template. Say I have
"Project Notes.dot" I want to guide the user to saving their notes as
"Project xxxx Notes.doc" where xxxx is a project number that the user
provides. (Bonus points if I can also put some of the user-supplied
information into the document properties like Keywords and Comments or
custom fields.)
TIA.
You could also look at
http://word.mvps.org/FAQs/MacrosVBA/ApplicationEvents.htm
and
http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm
but the Application Events has worked well for me.
There is also a section on that site on "Working with properties", see
http://word.mvps.org/FAQs/MacrosVBA/index.htm.
(it's the one under Working with Events...).
You can get info from the user via the InputBox function (see VBA's help on
that).
I think everything you need is there. Good luck.
Cheers
Rich
I appreciate the pointer but I get stuck on step 2 which says, "Rename
the Class Module from Class1 to ThisApplication" without any clue how
to do that. I've tried every menu option, a context menu in the
navigation pane, a context menu in the class window, highlighting
Class1 and pressing F2. Nothing gets met close to being able to
rename the class. I searched help for "how do I rename a class" and
got no useful results.
I guess I'm missing something fundamental. I followed those
directions except that I don't want my macro to be universal, I want
it only in a specific template so I put it there, not in the Word
startup directory. I have
Private Sub oApp_NewDocument(ByVal Doc As Document)
Dim Result
Result = InputBox("Title", "foo")
End Sub
which did nothing, so I moved my InputBox to the AutoExec():
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
Dim Result
Result = InputBox("Title", "foo")
End Sub
What I hope to see is when I double-click on the .dot containing this
macro that a InputBox would be displayed. I don't see anything.
I guess I'm missing something fundamental. I followed those
Sub AutoNew()
Dim Project as string
Project = InputBox("Enter the Project Number")
ActiveDocument.SaveAs "Project " & Project & " Notes.doc"
End Sub
--
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, originally posted via msnews.microsoft.com
"Chris Nelson" <chris.ne...@gmail.com> wrote in message
news:5887a207-c241-4ab6...@j19g2000vbp.googlegroups.com...
Yes! That's a great start. Thanks.
I need to build on this in two ways. First, I need to change all
instances of a sentinal string to the project number. I can spelunk
VBA help to figure out how to automate search and replease. Second,
I'd really like to be able to enter a project description, too. Is
there something like InputBox that lets me create more complex dialog
boxes where the user can enter multiple values? Another approach I've
considered is creating a Project Wizard but I have no idea how Office
wizards (like for resumes, etc.) are created.
That worked once or twice and stopped working. :-( I removed all my
recorded macros and other possible noise and it still doesn't work.
What you're describing is a UserForm, which is a custom dialog box with
associated VBA code. See
http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm for an
introduction.
--
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.
The first place I got this to work was in a template in my normal
template directory. Then I copied it to another directory where I
plan to be able to create documents by double-clicking on the .dot in
Explorer. I haven't touched the original test but it fails now, too.
Do they interact with Normal.dot somehow? Is there some global
environment I broke by cleaning up Normal.dot along the way?
Thanks. If I could get my macro to work at all now, I could go about
adding to it.
You should put the template in your User or Workgroup Templates folder so
that it is trusted and I would suggest that you use File>New to create new
documents.
As Jay said, a UserForm will allow you to enter more information at the time
of creating a new document and is preferrable in my opinion to the use of
multiple InputBox commands.
--
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, originally posted via msnews.microsoft.com
"Chris Nelson" <chris.ne...@gmail.com> wrote in message
news:af96bc2a-a6b3-425b...@z34g2000vbl.googlegroups.com...
I'd believe you if it never worked. But it worked for a while in my
non-template location and stopped working in my template folder, too.
> You should put the template in your User or Workgroup Templates folder so
> that it is trusted and I would suggest that you use File>New to create new
> documents.
That's really not practical for my application.
> As Jay said, a UserForm will allow you to enter more information at the time
> of creating a new document and is preferrable in my opinion to the use of
> multiple InputBox commands.
I agree. And if I can get a macro to execute again, I'll look into
UserForm.
I removed the AutoNew() macro and its module and added them back and
it works again. No clue why. VBA really needs a symbolic debugger.
Thanks. That's starting to work. Is there a way I can validate the
input? At least to make sure it's non-blank?
Sub AutoNew()
1 Dim Project As String
2 Project = InputBox("Enter the Project Number")
3 If Project <> "" Then
4 ActiveDocument.SaveAs "Project " & Project & " Notes.doc"
5 Else
6 MsgBox "Please Enter a valid Project Number."
7 GoTo 2
8 End If
End Sub
--
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, originally posted via msnews.microsoft.com
"Chris Nelson" <chris.ne...@gmail.com> wrote in message
news:18b8447f-36e4-4989...@n35g2000yqm.googlegroups.com...