I have a table in MSWord that contains names, a date, and non-numerical data. I'd like to write a macro that extracts this data and makes it so that when the user hits Save As, the suggested filename arranges the data in a particular order, separated by periods.
Here's what the table looks like:
First Column:
Date 04/10/13
Name 1 Arthur Z
Name 2 Bea Y
Title 1 Cars
Second Column:
Title 2 Boats
Company Burger King
Color Red
Name 3 Caroline X
I need the filename to be in the following format:
Burger King.Red.Y.Bea.04-10-13.Arthur Z.(extension)
The code I have:
Sub FileSaveAs()
ActiveDocument.Fields.Update
ActiveDocument.Fields.Update
'Updated twice because some of the fields that need
'to be updated rely on fields below it and since it
'doesn't take too long I didn't bother figuring out
'how to make it update backwards--but if anyone knows
'how, please lmk
Dim r As Range
Set r = ActiveDocument.Range
Dim fld As Field
Dim iCnt As Integer
For Each fld In ActiveDocument.Fields
'All this field and highlight stuff is to edit the
'document down--I have all this done
If fld.Type = wdFieldFormTextInput Then iCnt = iCnt + 1
Next
If iCnt >= 1 Then
Dim Response As VbMsgBoxResult
Response = MsgBox("Delete notes and shading?", vbYesNo + vbQuestion)
If Response = vbYes Then
With r.Find
.Highlight = True
.Forward = True
While .Execute
r.Delete
Wend
End With
For Each fld In ActiveDocument.Fields
fld.Select
If fld.Type = wdFieldFormTextInput Then
fld.Unlink
End If
Next
With Dialogs(wdDialogFileSaveAs)
.Name = "Burger King.Red.Y.Bea.04-10-13.Arthur Z.docm"
.Show
End With
EndUndoSaver
Exit Sub
ElseIf Response = vbNo Then
With Dialogs(wdDialogFileSaveAs)
.Name = "Burger King.Red.Y.Bea.04-10-13.Arthur Z.docm"
.Show
End With
End If
EndUndoSaver
Exit Sub
ElseIf iCnt = 0 Then
With Dialogs(wdDialogFileSaveAs)
.Name = "Burger King.Red.Y.Bea.04-10-13.Arthur Z.docm"
.Show
End With
End If
Set fld = Nothing
End Sub