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!

Re: specfic file name macro from form fields entries by Shauna

Shauna
Sun Dec 03 08:11:47 CST 2006

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


"TBolt" <jsed@hotmail.com> wrote in message
news:VJAch.68932$HD6.34464@tornado.southeast.rr.com...
>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!
>
>
>



Re: specfic file name macro from form fields entries by TBolt

TBolt
Sun Dec 03 11:15:35 CST 2006

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



"Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in message
news:uZcguUuFHHA.1912@TK2MSFTNGP03.phx.gbl...
> 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
>
>
> "TBolt" <jsed@hotmail.com> wrote in message
> news:VJAch.68932$HD6.34464@tornado.southeast.rr.com...
>>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!
>>
>>
>>
>
>



Re: specfic file name macro from form fields entries by Greg

Greg
Sun Dec 03 12:47:49 CST 2006

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.

"TBolt" <jsed@hotmail.com> wrote in message
news:XCDch.41610$nG1.19229@tornado.southeast.rr.com...
> 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
>
>
>
> "Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in message
> news:uZcguUuFHHA.1912@TK2MSFTNGP03.phx.gbl...
>> 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
>>
>>
>> "TBolt" <jsed@hotmail.com> wrote in message
>> news:VJAch.68932$HD6.34464@tornado.southeast.rr.com...
>>>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!
>>>
>>>
>>>
>>
>>
>
>



Re: specfic file name macro from form fields entries by TBolt

TBolt
Sun Dec 03 16:18:22 CST 2006

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


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:%235doIuwFHHA.4712@TK2MSFTNGP04.phx.gbl...
> 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.
>
> "TBolt" <jsed@hotmail.com> wrote in message
> news:XCDch.41610$nG1.19229@tornado.southeast.rr.com...
>> 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
>>
>>
>>
>> "Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in message
>> news:uZcguUuFHHA.1912@TK2MSFTNGP03.phx.gbl...
>>> 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
>>>
>>>
>>> "TBolt" <jsed@hotmail.com> wrote in message
>>> news:VJAch.68932$HD6.34464@tornado.southeast.rr.com...
>>>>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!
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Re: specfic file name macro from form fields entries by Greg

Greg
Sun Dec 03 21:21:21 CST 2006

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.


TBolt wrote:
> 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
>
>
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
> news:%235doIuwFHHA.4712@TK2MSFTNGP04.phx.gbl...
>> 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.
>>
>> "TBolt" <jsed@hotmail.com> wrote in message
>> news:XCDch.41610$nG1.19229@tornado.southeast.rr.com...
>>> 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
>>>
>>>
>>>
>>> "Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in
>>> message news:uZcguUuFHHA.1912@TK2MSFTNGP03.phx.gbl...
>>>> 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
>>>>
>>>>
>>>> "TBolt" <jsed@hotmail.com> wrote in message
>>>> news:VJAch.68932$HD6.34464@tornado.southeast.rr.com...
>>>>> 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!



Re: specfic file name macro from form fields entries by Tbolt

Tbolt
Sun Dec 03 21:55:36 CST 2006

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?

"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:eyZ9FN1FHHA.1276@TK2MSFTNGP04.phx.gbl...
> 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.
>
>
> TBolt wrote:
>> 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
>>
>>
>> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
>> news:%235doIuwFHHA.4712@TK2MSFTNGP04.phx.gbl...
>>> 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.
>>>
>>> "TBolt" <jsed@hotmail.com> wrote in message
>>> news:XCDch.41610$nG1.19229@tornado.southeast.rr.com...
>>>> 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
>>>>
>>>>
>>>>
>>>> "Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in
>>>> message news:uZcguUuFHHA.1912@TK2MSFTNGP03.phx.gbl...
>>>>> 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
>>>>>
>>>>>
>>>>> "TBolt" <jsed@hotmail.com> wrote in message
>>>>> news:VJAch.68932$HD6.34464@tornado.southeast.rr.com...
>>>>>> 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!
>
>




Re: specfic file name macro from form fields entries by Greg

Greg
Sun Dec 03 22:25:36 CST 2006

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.




Tbolt wrote:
> 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?
>
> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
> news:eyZ9FN1FHHA.1276@TK2MSFTNGP04.phx.gbl...
>> 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.
>>
>>
>> TBolt wrote:
>>> 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
>>>
>>>
>>> "Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
>>> news:%235doIuwFHHA.4712@TK2MSFTNGP04.phx.gbl...
>>>> 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.
>>>>
>>>> "TBolt" <jsed@hotmail.com> wrote in message
>>>> news:XCDch.41610$nG1.19229@tornado.southeast.rr.com...
>>>>> 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
>>>>>
>>>>>
>>>>>
>>>>> "Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in
>>>>> message news:uZcguUuFHHA.1912@TK2MSFTNGP03.phx.gbl...
>>>>>> 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
>>>>>>
>>>>>>
>>>>>> "TBolt" <jsed@hotmail.com> wrote in message
>>>>>> news:VJAch.68932$HD6.34464@tornado.southeast.rr.com...
>>>>>>> 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!