Microsoft Word Not Saving

joebrown116

New Member
Joined
Sep 7, 2017
Messages
2
Code:
Sub Test()

Dim DCM1 As String

DCM1 = Mid(ThisDocument.Name, 1, Len(ActiveDocument.Name) - 4)

    ActiveDocument.SaveAs2 FileName:="C:\Users\UI488820\Desktop\Logo" & DCM1 & "" & "test" & ".docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=False, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=14

End Sub

Get the 5251 error (can't remember exact number) saving the file path or file name . Here's some of the code above.

Please help!
 
Last edited by a moderator:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Here's the actual code if it helps.
Code:
Sub MailMerge2DOC()
Dim DokName As String
Dim DCM1 As String
DCM1 = Mid(ThisDocument.Name, 1, Len(ActiveDocument.Name) - 4)
'Set to First Record
ThisDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
'refresh
DocCheck2 = 0
DokName = 0
'limited
DocNo = 0 'limit start
'Restart Point
Restart:
If ThisDocument.MailMerge.DataSource.DataFields("Employee_Number").Value = DocCheck2 Then
MsgBox "Duplicate Detected! " & ThisDocument.MailMerge.DataSource.DataFields("Employee_Number").Value & " & " & DocCheck2 & ". If this is the last Payroll number in your Mail Merge then your Mail Merge is Complete."
Call MailMerge2PDF
Exit Sub
End If
'limiter
DocNo = DocNo + 1 '+1 to limiter
    With ThisDocument.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
            .LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
' Remember the wanted documentname
           DokName = .DataFields("Nickname").Value & " " & .DataFields("Last_name").Value & " " & .DataFields("Employee_Number").Value ' replace data fields with mail merge fields you want file name to be
        End With
Continue:
' Merge the active record
        .Execute Pause:=False
    End With
' Save then resulting document to DOC 'location to save files
    ActiveDocument.SaveAs2 FileName:="C:\Users\UI488820\Desktop\Logo" & DCM1 & Application.PathSeparator & DokName & ".docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=False, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=14
' Close the resulting document
If ActiveDocument <> ThisDocument Then
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Else
End If
'duplicate check
DocCheck2 = vbNullString
DocCheck2 = ThisDocument.MailMerge.DataSource.DataFields("Employee_Number").Value
' Load next record
    ThisDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
'limiter
If DocNo = 500 Then 'default set at 500
MsgBox "500 Limit Reached. Speak to Joe or go into programming and extend limit (replace all 500's with new limit)."
Exit Sub
End If
'Restart
GoTo Restart
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top