Saving my Doc after filling out the form

P

pieohpah

Hi there.

After almost finally finished with my form a new problem arised :)
The users that has to use this templeate will have problems with
saving the documents in the right manner so I want to try to make it a
lot easier for them:

1. I have 2 formfields "name0" and "class" that I would like to
include automatic as the documents name when saved - so the users only
need to press 1 button and decide where to save the file.
(ex: name0= Søren Vejle and class=9.b so the document should be named=
Søren Vejle 9.b.doc)

2. Would like to make some field in the end of my document that when
pressed saves the file? (the field should'nt be included when printing
the document!)

3. The users only concern has to be where to save this file - cause it
needs to be saved on different locations in our system.


I really hope someone will be able to help me out :)

Yours
Søren Vejle
 
J

Jay Freedman

Hi there.

After almost finally finished with my form a new problem arised :)
The users that has to use this templeate will have problems with
saving the documents in the right manner so I want to try to make it a
lot easier for them:

1. I have 2 formfields "name0" and "class" that I would like to
include automatic as the documents name when saved - so the users only
need to press 1 button and decide where to save the file.
(ex: name0= Søren Vejle and class=9.b so the document should be named=
Søren Vejle 9.b.doc)

2. Would like to make some field in the end of my document that when
pressed saves the file? (the field should'nt be included when printing
the document!)

3. The users only concern has to be where to save this file - cause it
needs to be saved on different locations in our system.


I really hope someone will be able to help me out :)

Yours
Søren Vejle

First tip: Don't put the button in the body of the document, precisely
because it's extra work to make it not print. Instead, add the button
to a toolbar for your template (in the Tools > Customize dialog, make
sure the "Save in" box is set to the name of your template). The
button will appear only in documents based on this particular
template.

Make the button run a macro like this (explanations follow the code):

Sub SaveToName()
Dim FileName As String

On Error GoTo BadFields

With ActiveDocument.FormFields
FileName = .Item("name0").Result & " " _
& .Item("class").Result
End With

On Error GoTo 0

' guard against empty fields
If Len(Trim(FileName)) = 0 Then
MsgBox "Please fill the Name and Class fields"
Exit Sub
End If

FileName = FileName & ".doc"

' set the Title field
With Dialogs(wdDialogFileSummaryInfo)
.Title = FileName
.Execute
End With

' open the Save As dialog
Dialogs(wdDialogFileSaveAs).Show

Exit Sub

BadFields:
MsgBox "The Name or Class field is missing"
End Sub

The idea is that whatever string you put into the Title field of the
File Properties dialog will be offered as the suggested filename the
first time the new document is saved (see
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm). That's
the part of the macro that follows the comment "set the Title field".
After that's done, the macro shows the File > Save As dialog, which
lets the user choose the folder to save the file (and possibly to edit
the suggested name).

The first part of the macro guards against the user forgetting to fill
any fields before clicking the button.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
P

pieohpah

First tip: Don't put the button in the body of the document, precisely
because it's extra work to make it not print. Instead, add the button
to a toolbar for your template (in the Tools > Customize dialog, make
sure the "Save in" box is set to the name of your template). The
button will appear only in documents based on this particular
template.

Make the button run a macro like this (explanations follow the code):

Sub SaveToName()
Dim FileName As String

On Error GoTo BadFields

With ActiveDocument.FormFields
FileName = .Item("name0").Result & " " _
& .Item("class").Result
End With

On Error GoTo 0

' guard against empty fields
If Len(Trim(FileName)) = 0 Then
MsgBox "Please fill the Name and Class fields"
Exit Sub
End If

FileName = FileName & ".doc"

' set the Title field
With Dialogs(wdDialogFileSummaryInfo)
.Title = FileName
.Execute
End With

' open the Save As dialog
Dialogs(wdDialogFileSaveAs).Show

Exit Sub

BadFields:
MsgBox "The Name or Class field is missing"
End Sub

The idea is that whatever string you put into the Title field of the
File Properties dialog will be offered as the suggested filename the
first time the new document is saved (seehttp://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm). That's
the part of the macro that follows the comment "set the Title field".
After that's done, the macro shows the File > Save As dialog, which
lets the user choose the folder to save the file (and possibly to edit
the suggested name).

The first part of the macro guards against the user forgetting to fill
any fields before clicking the button.

--
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.- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -

Hi Jay.

The macro works fine but im having difficulties getting the button in
the quick acces toolbar working.
Have put one in but it stays like this even in the normal templeates?
Tried to set the button only to work in the form files but I cant - it
will only let me use the default settings.
Im using woord 2007.

Yours
Søren Vejle
 
J

Jay Freedman

Hi Jay.

The macro works fine but im having difficulties getting the button in
the quick acces toolbar working.
Have put one in but it stays like this even in the normal templeates?
Tried to set the button only to work in the form files but I cant - it
will only let me use the default settings.
Im using woord 2007.

Yours
Søren Vejle

In the Word Options > Customize dialog, set the dropdown above the
left-hand list ("Choose commands from") to Macros. Set the dropdown
above the right-hand list ("Customize Quick Access Toolbar") to the
name of your template. Then select the macro and click the Add button
to pop it over to the right-hand list (which is probably empty at
first).

Then you can click the Modify button and change the display name and
button face.

The button should appear only when you're working on a document based
on the template.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
P

pieohpah

In the Word Options > Customize dialog, set the dropdown above the
left-hand list ("Choose commands from") to Macros. Set the dropdown
above the right-hand list ("Customize Quick Access Toolbar") to the
name of your template. Then select the macro and click the Add button
to pop it over to the right-hand list (which is probably empty at
first).

Then you can click the Modify button and change the display name and
button face.

The button should appear only when you're working on a document based
on the template.

--
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.

Hi Jay.

Now i have the button made :) works - thx. But the templeate needs to
be working under Word2003 aswell - when saving the templeate in 2003
format, word writes that the button cant be moved over cause the
2003format is to old - what can I do to make it work prefect in 2003
versions aswell?

Yours
Søren vejle
 
J

Jay Freedman

Hi Jay.

Now i have the button made :) works - thx. But the templeate needs to
be working under Word2003 aswell - when saving the templeate in 2003
format, word writes that the button cant be moved over cause the
2003format is to old - what can I do to make it work prefect in 2003
versions aswell?

Yours
Søren vejle

I don't think there's anything you can do in Word 2007 to make the
button backward-compatible to earlier versions. The QAT is new, and
the earlier versions don't know anything about it.

If you edit the template in Word 2003 and create a custom toolbar
there, then open the template or a document based on the template in
Word 2007, the toolbar will be hosted in the Add-Ins tab that will now
appear. This isn't ideal, but it's the only way to move buttons
between versions.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top