the X.
complex. Have any suggestions on a good book for begginers?
Post by Greg MaxeyTBolt,
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 TBoltThat 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 MaxeyTBolt,
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 TBoltThanks, 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 KellyHi 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 TBoltI 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!