W
Walter
I'm creating about 300 to 500 merged documents per week, each from a different source. After each batch of 25 or so, I (hope to, but haven't gotten that far because of this problem) use another macro to put all of them together in one table to email to the PHB. I want to name the files as date (mmddyy) followed by a counter. Here is the code I'm using:
Sub AutoClose()
Dim myName As String, strResponse As String, i As Integer
i = 1
Mask = "MMddyy"
Do While ActiveDocument.Saved = False
myName = "I:\JEMSForm\RW5557\" & Format(Date, Mask) & i
strResponse = MsgBox(myName, vbYesNo, "Save As")
If strResponse = 6 Then
ActiveDocument.SaveAs myName, wdFormatDocument
Else
i = InputBox("Enter counter")
End If
Loop
End Sub
I've also tried the same code in a Private Sub Document_Close(). It works fine- pops up a msgbox w/default name and asks if I want to save with that name. If I click no, then it pops up the inputbox, where I put in the counter I want to use. (This works ok because the list documents I have to merge are numbered. unfortunately, the number is only on paper, not in the data source, so I can't get jsut merger it in.) Then up comes the msgbox with the new name. I click 'Yes' and it saves. Problem is, the macro is running when the document opens, before the merge executes, and the file is saved with merge codes instead of merged data. Then, when I try to close the document, I get the regular save before closing dialog, and have to go hunting for the network directory....
Where, oh where have I gone astray?
Sub AutoClose()
Dim myName As String, strResponse As String, i As Integer
i = 1
Mask = "MMddyy"
Do While ActiveDocument.Saved = False
myName = "I:\JEMSForm\RW5557\" & Format(Date, Mask) & i
strResponse = MsgBox(myName, vbYesNo, "Save As")
If strResponse = 6 Then
ActiveDocument.SaveAs myName, wdFormatDocument
Else
i = InputBox("Enter counter")
End If
Loop
End Sub
I've also tried the same code in a Private Sub Document_Close(). It works fine- pops up a msgbox w/default name and asks if I want to save with that name. If I click no, then it pops up the inputbox, where I put in the counter I want to use. (This works ok because the list documents I have to merge are numbered. unfortunately, the number is only on paper, not in the data source, so I can't get jsut merger it in.) Then up comes the msgbox with the new name. I click 'Yes' and it saves. Problem is, the macro is running when the document opens, before the merge executes, and the file is saved with merge codes instead of merged data. Then, when I try to close the document, I get the regular save before closing dialog, and have to go hunting for the network directory....
Where, oh where have I gone astray?