View Single Post
 
Old 07-19-2016, 10:22 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you are using a macro to get the username, then why not use the macro to test if the file exists and write the appropriate field to the merge document? E.g. as follows, which wites to the cursor, though it wouldn't be much of a stretch to write it to a bookmark or specific range.
Code:
Sub WriteField()
Dim strName As String
strName = Environ("UserName")
If FileExists("Q:\Letters\Signatures\" & strName & ".docx") Then
    ActiveDocument.Fields.Add Selection.Range, wdFieldIncludeText, """Q:\\Letters\\Signatures\\" & strName & ".docx""", False
Else
   ActiveDocument.Fields.Add Selection.Range, wdFieldIncludeText, """Q:\\Letters\\Signatures\\default.docx""", False
End If
End Sub

Private Function FileExists(strFullName As String) As Boolean
'Graham Mayor - http://www.gmayor.com
'strFullName is the name with path of the file to check
Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(strFullName) Then
        FileExists = True
    Else
        FileExists = False
    End If
lbl_Exit:
    Set fso = Nothing
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote