Discussion:
specfic file name macro from form fields entries
(too old to reply)
TBolt
2006-12-03 13:58:13 UTC
Permalink
I want a document to automatically have the file name entered when an
employee clicks save or the save as. The file name will be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?

I also would like to these save at a specific location on a network drive.

I have no experience in VB.

Word 2003



Any help would be appreciated!
Shauna Kelly
2006-12-03 14:11:47 UTC
Permalink
Hi TBolt

See
How to set the default suggested filename to be displayed by the Save As
dialog the first time a user saves a new document
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by TBolt
I want a document to automatically have the file name entered when an
employee clicks save or the save as. The file name will be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?
I also would like to these save at a specific location on a network drive.
I have no experience in VB.
Word 2003
Any help would be appreciated!
TBolt
2006-12-03 17:15:35 UTC
Permalink
Thanks, but it does not seem to work. I am wanting to take what is entered
into Text6 (Name) and Text70 (Department) field and combine those entries
into an auto filename eg. JohnWarehouse.
I have searched and found code that does close to what I want. It uses one
form field to make a file name where as I want two form fields.


Sub FileSave()

If ActiveDocument.Type = 0 And ActiveDocument.Name =
ActiveDocument.FullName Then

If Len(Trim(ActiveDocument.FormFields("Text6").Result)) = 0 Then

MsgBox "You must enter a name into the form field", vbOKOnly +
vbExclamation, "Error"

Exit Sub

End If

With Application

With .Dialogs(wdDialogFileSummaryInfo)

.Title = ActiveDocument.FormFields("Text6").Result

.Execute

End With

With .Dialogs(wdDialogFileSaveAs)

If .Display = True Then .Execute

End With

End With

Else

ActiveDocument.Save

End If

End Sub



Sub FileSaveAs()

If ActiveDocument.Name = ActiveDocument.FullName Then

Call FileSave

Else

With Application.Dialogs(wdDialogFileSaveAs)

If .Display = True Then

.Execute

End If

End With

End If

End Sub
Post by Shauna Kelly
Hi TBolt
See
How to set the default suggested filename to be displayed by the Save As
dialog the first time a user saves a new document
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by TBolt
I want a document to automatically have the file name entered when an
employee clicks save or the save as. The file name will be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?
I also would like to these save at a specific location on a network drive.
I have no experience in VB.
Word 2003
Any help would be appreciated!
Greg Maxey
2006-12-03 18:47:49 UTC
Permalink
TBolt,

You can adapt that code easy enough:

Sub FileSave()
Dim myString As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If oDoc.Type = 0 And oDoc.Name = oDoc.FullName Then
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.", _
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
Thanks, but it does not seem to work. I am wanting to take what is entered
into Text6 (Name) and Text70 (Department) field and combine those entries
into an auto filename eg. JohnWarehouse.
I have searched and found code that does close to what I want. It uses one
form field to make a file name where as I want two form fields.
Sub FileSave()
If ActiveDocument.Type = 0 And ActiveDocument.Name =
ActiveDocument.FullName Then
If Len(Trim(ActiveDocument.FormFields("Text6").Result)) = 0 Then
MsgBox "You must enter a name into the form field", vbOKOnly +
vbExclamation, "Error"
Exit Sub
End If
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = ActiveDocument.FormFields("Text6").Result
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
ActiveDocument.Save
End If
End Sub
Sub FileSaveAs()
If ActiveDocument.Name = ActiveDocument.FullName Then
Call FileSave
Else
With Application.Dialogs(wdDialogFileSaveAs)
If .Display = True Then
.Execute
End If
End With
End If
End Sub
Post by Shauna Kelly
Hi TBolt
See
How to set the default suggested filename to be displayed by the Save As
dialog the first time a user saves a new document
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by TBolt
I want a document to automatically have the file name entered when an
employee clicks save or the save as. The file name will be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?
I also would like to these save at a specific location on a network drive.
I have no experience in VB.
Word 2003
Any help would be appreciated!
TBolt
2006-12-03 22:18:22 UTC
Permalink
That works very good but I did notice it only works when only the "save" is
clicked and not when "save as" or when someone would close or click the (x)
to close. Is it possible to assign the code to a command button to save. I
tried putting the code in the click event of the command button and it did
nothing.
Thanks in advance
Post by Greg Maxey
TBolt,
Sub FileSave()
Dim myString As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If oDoc.Type = 0 And oDoc.Name = oDoc.FullName Then
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.", _
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
Thanks, but it does not seem to work. I am wanting to take what is
entered into Text6 (Name) and Text70 (Department) field and combine those
entries into an auto filename eg. JohnWarehouse.
I have searched and found code that does close to what I want. It uses
one form field to make a file name where as I want two form fields.
Sub FileSave()
If ActiveDocument.Type = 0 And ActiveDocument.Name =
ActiveDocument.FullName Then
If Len(Trim(ActiveDocument.FormFields("Text6").Result)) = 0 Then
MsgBox "You must enter a name into the form field", vbOKOnly +
vbExclamation, "Error"
Exit Sub
End If
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = ActiveDocument.FormFields("Text6").Result
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
ActiveDocument.Save
End If
End Sub
Sub FileSaveAs()
If ActiveDocument.Name = ActiveDocument.FullName Then
Call FileSave
Else
With Application.Dialogs(wdDialogFileSaveAs)
If .Display = True Then
.Execute
End If
End With
End If
End Sub
Post by Shauna Kelly
Hi TBolt
See
How to set the default suggested filename to be displayed by the Save As
dialog the first time a user saves a new document
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by TBolt
I want a document to automatically have the file name entered when an
employee clicks save or the save as. The file name will be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?
I also would like to these save at a specific location on a network drive.
I have no experience in VB.
Word 2003
Any help would be appreciated!
Greg Maxey
2006-12-04 03:21:21 UTC
Permalink
TBolt,

I don't think you want to use the built in FileSave and FileSaveAs commands
for this purpose. Consider what would happen if you wanted to save a file
that didn't have a formfield Text6 and Text70.

You might consider assigning this code to a menu, toolbar, or macrobutton:

Sub myFileSave()
Dim myString As String
Dim oDocName As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.", vbOKOnly +
vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
oDocName = oDoc.Name
oDocName = Left(oDocName, InStrRev(oDocName, ".") - 1)
If oDocName <> myString Then
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
.Name = myString
.Show
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
That works very good but I did notice it only works when only the
"save" is clicked and not when "save as" or when someone would close
or click the (x) to close. Is it possible to assign the code to a
command button to save. I tried putting the code in the click event
of the command button and it did nothing.
Thanks in advance
Post by Greg Maxey
TBolt,
Sub FileSave()
Dim myString As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If oDoc.Type = 0 And oDoc.Name = oDoc.FullName Then
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.", _
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
Thanks, but it does not seem to work. I am wanting to take what is
entered into Text6 (Name) and Text70 (Department) field and combine
those entries into an auto filename eg. JohnWarehouse.
I have searched and found code that does close to what I want. It
uses one form field to make a file name where as I want two form
fields. Sub FileSave()
If ActiveDocument.Type = 0 And ActiveDocument.Name =
ActiveDocument.FullName Then
If Len(Trim(ActiveDocument.FormFields("Text6").Result)) = 0
Then MsgBox "You must enter a name into the form field",
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = ActiveDocument.FormFields("Text6").Result
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
ActiveDocument.Save
End If
End Sub
Sub FileSaveAs()
If ActiveDocument.Name = ActiveDocument.FullName Then
Call FileSave
Else
With Application.Dialogs(wdDialogFileSaveAs)
If .Display = True Then
.Execute
End If
End With
End If
End Sub
Post by Shauna Kelly
Hi TBolt
See
How to set the default suggested filename to be displayed by the
Save As dialog the first time a user saves a new document
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by TBolt
I want a document to automatically have the file name entered
when an employee clicks save or the save as. The file name will
be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?
I also would like to these save at a specific location on a network drive.
I have no experience in VB.
Word 2003
Any help would be appreciated!
Tbolt
2006-12-04 03:55:36 UTC
Permalink
So I could add this code to a cammand button named "Save" (macro button
the same as a command button?)and it would bring up the dialog box with the
entries from Text6 and Text70 as the file name?

I am thinking that if I put a command button on the form for people to click
it they would not like click save as on the menue or press the X.

I am completely new at this VB and am finding it intresting but complex.
Have any suggestions on a good book for begginers?
Post by Greg Maxey
TBolt,
I don't think you want to use the built in FileSave and FileSaveAs
commands for this purpose. Consider what would happen if you wanted to
save a file that didn't have a formfield Text6 and Text70.
Sub myFileSave()
Dim myString As String
Dim oDocName As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.", vbOKOnly +
vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
oDocName = oDoc.Name
oDocName = Left(oDocName, InStrRev(oDocName, ".") - 1)
If oDocName <> myString Then
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
.Name = myString
.Show
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
That works very good but I did notice it only works when only the
"save" is clicked and not when "save as" or when someone would close
or click the (x) to close. Is it possible to assign the code to a
command button to save. I tried putting the code in the click event
of the command button and it did nothing.
Thanks in advance
Post by Greg Maxey
TBolt,
Sub FileSave()
Dim myString As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If oDoc.Type = 0 And oDoc.Name = oDoc.FullName Then
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.", _
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
Thanks, but it does not seem to work. I am wanting to take what is
entered into Text6 (Name) and Text70 (Department) field and combine
those entries into an auto filename eg. JohnWarehouse.
I have searched and found code that does close to what I want. It
uses one form field to make a file name where as I want two form
fields. Sub FileSave()
If ActiveDocument.Type = 0 And ActiveDocument.Name =
ActiveDocument.FullName Then
If Len(Trim(ActiveDocument.FormFields("Text6").Result)) = 0
Then MsgBox "You must enter a name into the form field",
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = ActiveDocument.FormFields("Text6").Result
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
ActiveDocument.Save
End If
End Sub
Sub FileSaveAs()
If ActiveDocument.Name = ActiveDocument.FullName Then
Call FileSave
Else
With Application.Dialogs(wdDialogFileSaveAs)
If .Display = True Then
.Execute
End If
End With
End If
End Sub
Post by Shauna Kelly
Hi TBolt
See
How to set the default suggested filename to be displayed by the
Save As dialog the first time a user saves a new document
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by TBolt
I want a document to automatically have the file name entered
when an employee clicks save or the save as. The file name will
be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?
I also would like to these save at a specific location on a network drive.
I have no experience in VB.
Word 2003
Any help would be appreciated!
Greg Maxey
2006-12-04 04:25:36 UTC
Permalink
TBolt,

If the macro were assigned to a menu command, toolbar command, or
macrobutton it would perform the same action that it performs now. That is,
if the file name doesnt' match the text in Text6 and Text70 it will display
the SaveAs dialog. To see the code at work, you can step through it line
for line using F8.

See these links:

http://word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm and
http://word.mvps.org/faqs/tblsfldsfms/UsingMacroButton.htm
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

I am not completely new at VBA and like you I also find it complex ;-). I
have never read a book on VBA. Reading the articles on Macors in the Word
MVP FAQ site is a good place to start.
Post by Tbolt
So I could add this code to a cammand button named "Save" (macro
button the same as a command button?)and it would bring up the dialog
box with the entries from Text6 and Text70 as the file name?
I am thinking that if I put a command button on the form for people
to click it they would not like click save as on the menue or press
the X.
I am completely new at this VB and am finding it intresting but
complex. Have any suggestions on a good book for begginers?
Post by Greg Maxey
TBolt,
I don't think you want to use the built in FileSave and FileSaveAs
commands for this purpose. Consider what would happen if you wanted
to save a file that didn't have a formfield Text6 and Text70.
You might consider assigning this code to a menu, toolbar, or
macrobutton: Sub myFileSave()
Dim myString As String
Dim oDocName As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.",
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
oDocName = oDoc.Name
oDocName = Left(oDocName, InStrRev(oDocName, ".") - 1)
If oDocName <> myString Then
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
.Name = myString
.Show
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
That works very good but I did notice it only works when only the
"save" is clicked and not when "save as" or when someone would close
or click the (x) to close. Is it possible to assign the code to a
command button to save. I tried putting the code in the click event
of the command button and it did nothing.
Thanks in advance
Post by Greg Maxey
TBolt,
Sub FileSave()
Dim myString As String
Dim oDoc As Word.Document
Dim oFF As FormFields
Set oDoc = ActiveDocument
Set oFF = oDoc.FormFields
If oDoc.Type = 0 And oDoc.Name = oDoc.FullName Then
If Len(Trim(oFF("Text6").Result)) = 0 Or _
Len(Trim(oFF("Text70").Result)) = 0 Then
MsgBox "You must enter text into both formfields 6 and 70.", _
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
myString = oFF("Text6").Result + oFF("Text70").Result
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = myString
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
oDoc.Save
End If
End Sub
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by TBolt
Thanks, but it does not seem to work. I am wanting to take what is
entered into Text6 (Name) and Text70 (Department) field and
combine those entries into an auto filename eg. JohnWarehouse.
I have searched and found code that does close to what I want. It
uses one form field to make a file name where as I want two form
fields. Sub FileSave()
If ActiveDocument.Type = 0 And ActiveDocument.Name =
ActiveDocument.FullName Then
If Len(Trim(ActiveDocument.FormFields("Text6").Result)) = 0
Then MsgBox "You must enter a name into the form field",
vbOKOnly + vbExclamation, "Error"
Exit Sub
End If
With Application
With .Dialogs(wdDialogFileSummaryInfo)
.Title = ActiveDocument.FormFields("Text6").Result
.Execute
End With
With .Dialogs(wdDialogFileSaveAs)
If .Display = True Then .Execute
End With
End With
Else
ActiveDocument.Save
End If
End Sub
Sub FileSaveAs()
If ActiveDocument.Name = ActiveDocument.FullName Then
Call FileSave
Else
With Application.Dialogs(wdDialogFileSaveAs)
If .Display = True Then
.Execute
End If
End With
End If
End Sub
Post by Shauna Kelly
Hi TBolt
See
How to set the default suggested filename to be displayed by the
Save As dialog the first time a user saves a new document
http://www.word.mvps.org/FAQs/MacrosVBA/SetDefFilename.htm
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by TBolt
I want a document to automatically have the file name entered
when an employee clicks save or the save as. The file name will
be a combination of
two form fields (Text6 and Text70). Is there a way to get the entries from
these two fields and append them into one file name?
I also would like to these save at a specific location on a network drive.
I have no experience in VB.
Word 2003
Any help would be appreciated!
Loading...