Fixes & Troubleshooting

Fix: Word Documents Overwrite Each Other in Shared Output Folders

Two people can choose the same free filename in a shared folder, even after a VBA collision check. Learn why that happens and use a free Word macro with a new GUID for every DOCX/PDF pair.

Shared-folder collisions
Free Word VBA
Unique DOCX + PDF pairs
Honest concurrency limits

Quick answer

If several users export Word documents to the same network folder, checking whether Report.docx exists is not enough. Two users can see a free name at the same moment and then both try to save it. For independent manual runs, generate a new GUID-based name for each save, and use that same name for the DOCX/PDF pair. The example below is a save-time utility for an already completed Word document, not an Excel-to-Word batch generator.

Important distinction

Dir$() checks the filesystem. A GUID makes accidental name duplication extraordinarily unlikely. Neither step atomically locks the destination. For a strict no-collision guarantee among simultaneous writers, use an exclusive-create/locking mechanism or separate per-user output folders.

Why shared folders make collisions harder

Shared network output is convenient for document review, but ordinary batch naming rules are usually designed for one writer at a time.

Two users can choose the same name

Both computers read the same folder and see Report_0008.docx as available before either save completes.

DOCX and PDF can diverge

Checking only the Word filename can leave a PDF with the same stem already present, making a subsequent export unsafe.

Files can be locked or unavailable

Permissions, network interruptions and a document opened elsewhere can prevent a save even when the filename looks free.

Auditability becomes weaker

If two exports share a name or one PDF is missing, reviewers may no longer know which output belongs to which run.

The race condition that a simple counter cannot fix

A counter works for sequential exports. It does not give two Word processes exclusive ownership of a filename.

Unsafe: check, then save

User A sees Report_0001.docx is free. User B sees the same thing. Both try SaveAs2 with Report_0001.docx. A prompt, failure or overwritten output may result depending on the environment.

Better: independent unique tokens

Each user generates a different GUID and creates a pair such as Report_20261115_193500_{GUID}.docx plus the matching PDF. They no longer compete for the next shared counter.

If only one process writes to the folder, use the simpler duplicate-filename VBA fix. This article addresses multiple independent writers.

A safer shared-folder export workflow

Use a path you can access, generate the filename locally, then save the same stem as DOCX and PDF.

1. Prepare an existing folder

Ask your administrator for a writable UNC path such as \\server\team\outputs. Verify access from each PC. A local C:\Shared\Outputs folder on two PCs is not automatically the same shared destination; use an actual UNC path or properly mapped network drive. The macro does not attempt to create unknown network shares.

2. Keep a human-readable label

Use a short record or document label such as Invoice-1042, with unsupported Windows filename characters removed.

3. Append time and GUID

Use the timestamp to help people browse the folder and the Windows-generated GUID to avoid competing over sequential counters.

4. Save and verify the pair

Write the DOCX, then export the matching PDF. If PDF generation fails, keep the DOCX and inspect the partial output before running again.

Resulting files

For illustration, two independent users can produce different stems even within the same second:

\\server\team\outputs\
  Invoice-1042_20261115_193500_4F0B7D391C8A42DCA93BE462C11F0D27.docx
  Invoice-1042_20261115_193500_4F0B7D391C8A42DCA93BE462C11F0D27.pdf
  Invoice-1042_20261115_193500_B8E14511D0F24CA79A32C71B05E2D904.docx
  Invoice-1042_20261115_193500_B8E14511D0F24CA79A32C71B05E2D904.pdf

These are illustrative 32-character GUID values. Each real run generates a new value; do not reuse the identifiers shown here.

How to test it with two computers

Start with a copy of a non-sensitive Word document, not a live report or a production template.

Run twice on one computer

Run the macro from the completed Word document twice. Verify that filenames differ and no previous DOCX or PDF was overwritten.

Run from two different PCs

Give both computers the same destination and document label. Start the macros at roughly the same time; confirm unique stems and matched pairs.

Test access and interruption

Try a folder without write permission and an unavailable network path. The macro should report the failure, not pretend output succeeded.

Check partial PDFs

If export fails after DOCX saving, inspect the folder for a DOCX without its PDF. A second run creates a new name rather than repairing the old pair.

Before blaming the shared folder: check your source data

In an Excel-driven batch, a missing record ID, duplicate values, or an incorrectly mapped filename field can cause many documents to fall back to Report.docx. Check the row values and the field/tag mapping first. To isolate the problem, test a single document with a manually chosen unique label, then compare it with the filenames produced from Excel.

This standalone Word macro asks for the label directly; it does not read Excel columns or repair broken template tags. For sequential batch naming, see the dedicated duplicate-output fix.

Free Word VBA: unique shared-folder DOCX/PDF names

This complete Word macro uses the Windows CoCreateGuid API to generate a new 32-character hexadecimal ID for each save. It preserves a human-readable label and assigns one matching stem to the DOCX and PDF.

Setup

In Microsoft Word Desktop on Windows, open the VBA editor and paste this code into a standard module (for example in your trusted Normal.dotm). Open a finished document and save the original first. Run SaveSharedCopyWithUniqueName, enter the existing UNC or mapped-network destination explicitly (the field starts empty), and optionally enter a record label. The current Word document becomes the newly saved output document after SaveAs2.

Option Explicit

' Paste into a standard Word VBA module in a trusted .dotm template.
' Normal.dotm is also possible if your organization's policy allows it.
' Open a FINISHED document and save its original copy first.
' This macro saves the active document as a new DOCX/PDF pair.
' Each pair receives a timestamp and a new Windows GUID.
' It does not provide an atomic network-wide reservation/lock.

Private Type GuidValue
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(0 To 7) As Byte
End Type

#If VBA7 Then
    Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" _
        (ByRef id As GuidValue) As Long
#Else
    Private Declare Function CoCreateGuid Lib "ole32.dll" _
        (ByRef id As GuidValue) As Long
#End If

Public Sub SaveSharedCopyWithUniqueName()
    Dim doc As Document
    Dim folder As String, labelText As String
    Dim stem As String, docxPath As String, pdfPath As String
    Dim attempt As Long, savedDocx As Boolean
    Dim details As String

    On Error GoTo Failed
    Set doc = ActiveDocument
    If Len(doc.Path) = 0 Then
        Err.Raise vbObjectError + 301, , _
            "Save the original Word document locally before running."
    End If

    folder = Trim$(InputBox( _
        "Enter an EXISTING shared output folder (for example, \\\\server\\team\\outputs).", _
        "Destination folder", ""))
    If Len(folder) = 0 Then Exit Sub
    Do While Len(folder) > 3 And Right$(folder, 1) = "\"
        folder = Left$(folder, Len(folder) - 1)
    Loop
    If Len(Dir$(folder, vbDirectory)) = 0 Then
        Err.Raise vbObjectError + 302, , _
            "Folder not found or unavailable: " & folder
    End If
    If (GetAttr(folder) And vbDirectory) = 0 Then
        Err.Raise vbObjectError + 305, , "Not a folder: " & folder
    End If

    labelText = InputBox( _
        "Optional record or document label (for example, Report-1042).", _
        "Filename label", "Report")
    labelText = SafeFilePart(labelText)
    If Len(labelText) = 0 Then labelText = "Report"

    ' A GUID makes independent users exceedingly unlikely to choose
    ' the same filename; it is not an exclusive file-creation lock.
    For attempt = 1 To 5
        stem = Left$(labelText, 55) & "_" & _
               Format$(Now, "yyyymmdd_hhnnss") & "_" & NewGuidHex()
        docxPath = folder & "\" & stem & ".docx"
        pdfPath = folder & "\" & stem & ".pdf"
        If Len(Dir$(docxPath)) = 0 And Len(Dir$(pdfPath)) = 0 Then
            Exit For
        End If
    Next attempt
    If attempt > 5 Then
        Err.Raise vbObjectError + 303, , _
            "Could not choose an unused filename."
    End If

    doc.SaveAs2 FileName:=docxPath, FileFormat:=wdFormatXMLDocument, _
                AddToRecentFiles:=False
    savedDocx = True
    doc.ExportAsFixedFormat OutputFileName:=pdfPath, _
                            ExportFormat:=wdExportFormatPDF, _
                            OpenAfterExport:=False

    MsgBox "Created matching DOCX and PDF:" & vbCrLf & _
           docxPath & vbCrLf & pdfPath & vbCrLf & vbCrLf & _
           "The active document is now saved under the output name.", _
           vbInformation
    Exit Sub

Failed:
    details = Err.Description
    If savedDocx Then
        details = details & vbCrLf & vbCrLf & _
                  "A DOCX may already exist without its PDF:" & _
                  vbCrLf & docxPath & vbCrLf & _
                  "Inspect the output before rerunning."
    End If
    MsgBox "Output not completed: " & details, vbExclamation
End Sub

Private Function NewGuidHex() As String
    Dim g As GuidValue, i As Long, result As String
    If CoCreateGuid(g) <> 0 Then
        Err.Raise vbObjectError + 304, , "Windows GUID generation failed."
    End If
    result = Right$("00000000" & Hex$(g.Data1), 8) & _
             Right$("0000" & Hex$(CLng(g.Data2) And &HFFFF&), 4) & _
             Right$("0000" & Hex$(CLng(g.Data3) And &HFFFF&), 4)
    For i = 0 To 7
        result = result & Right$("0" & Hex$(g.Data4(i)), 2)
    Next i
    NewGuidHex = result
End Function

Private Function SafeFilePart(ByVal value As String) As String
    Dim forbidden As Variant, ch As Variant, i As Long
    Dim text As String, rootName As String
    text = Trim$(value)
    forbidden = Array("\", "/", ":", "*", "?", Chr$(34), _
                      "<", ">", "|")
    For Each ch In forbidden
        text = Replace$(text, CStr(ch), "_")
    Next ch
    For i = 0 To 31
        text = Replace$(text, Chr$(i), "_")
    Next i
    Do While Len(text) > 0
        If Right$(text, 1) <> "." And Right$(text, 1) <> " " Then _
            Exit Do
        text = Left$(text, Len(text) - 1)
    Loop
    text = Left$(text, 55)
    If Len(text) = 0 Then
        SafeFilePart = ""
        Exit Function
    End If
    rootName = UCase$(Split(text, ".")(0))
    Select Case rootName
        Case "CON", "PRN", "AUX", "NUL", "COM1", "COM2", _
             "COM3", "COM4", "COM5", "COM6", "COM7", _
             "COM8", "COM9", "LPT1", "LPT2", "LPT3", _
             "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
            text = "_" & text
    End Select
    SafeFilePart = text
End Function

The macro does not generate documents from Excel rows; it saves the active, already populated Word document. To automate Excel-to-Word generation, combine this unique-name concept with a separate verified template-filling workflow. Do not enable macros from untrusted documents.

Where this approach still has limits

GUID-based names are a practical answer to independently running Word users, not a replacement for network storage coordination.

A GUID is not a file lock

GUID collisions are extraordinarily unlikely, but a save is not an atomic reservation. Strict concurrency guarantees require exclusive file creation, a locking service, or separate writer directories.

Network outages still interrupt output

An unavailable SMB share, inadequate permissions, and Windows path limits can still stop SaveAs2 or PDF export.

PDF generation is a separate step

Word may save the DOCX and fail to export its PDF. This macro warns you but does not perform transaction rollback or an automatic repair.

Original document state matters

The macro runs on ActiveDocument. Save the original first, since the active Word document takes on the new filename when SaveAs2 completes.

The macro displays the saved paths in Word but does not write a persistent audit log. If your team requires one, add a separate reliable logging step.

For planned naming conventions, see how to organize output filenames. For per-row folder structure, see Excel-controlled output folders.

Free VBA vs DocxForge Pro Factory for recurring batches

The free macro above helps save one completed Word document to a shared folder with an extremely unlikely-to-repeat name. DocxForge Pro Factory addresses a different need: recurring Excel-driven Word/PDF batch generation, template data mapping and configurable output naming without maintaining a full VBA generator. Its naming options are not proof of exclusive network-file locking.

Use free Word VBA for an occasional shared save

If users finish documents individually and only need filenames that are extremely unlikely to collide, the GUID macro may be enough.

Use DocxForge Pro Factory for repeat batches

Configure Excel-driven Word templates, filename settings and optional PDF output from the Windows desktop interface instead of maintaining your own full batch script.

Do not confuse naming with locking

The Factory naming settings screen does not establish strict multi-user network locking. Confirm any concurrency guarantee separately before relying on a shared destination.

Know what the suite requires

DocxForge Pro runs locally on Windows and requires Microsoft Word Desktop for document generation and PDF export. Actual processing time depends on PC hardware and document complexity.

DocxForge Pro Factory Settings screen showing output filename field and naming options
DocxForge Pro Factory Settings: configure output naming without editing VBA. The screen does not prove simultaneous-user locking.
DocxForge Pro Factory Documents screen showing DOCX and optional PDF generation
DocxForge Pro Factory Documents: Word templates and optional PDF output in a local workflow. Check your network-sharing policy separately.

Use the GUID macro when individual users need unique shared-folder names. For ongoing Excel-to-Word/PDF production, where the time-consuming task is preparing many documents rather than coordinating concurrent writes, explore DocxForge Pro Factory and its plans. DocxForge Pro Contractor is also included for controlled case-document workflows.

Frequently asked questions

The key differences between a naming check, a unique ID and a true shared-folder lock.

Why can a shared folder overwrite Word files even when my macro checks Dir?

Two users can check the same filename before either saves. Dir reports what exists at the moment of the check; it does not reserve a name. This is a race condition.

Is adding _2 or a sequential counter enough for multiple users?

It is useful for sequential runs, but not a strict concurrency solution. Two processes can choose the same next number. Use a unique token per run or a storage system with atomic reservations.

Why does the free Word macro use a GUID?

Windows generates a new 128-bit identifier for each save attempt, so two independent users are extraordinarily unlikely to choose an identical base name even if they start together. It is still not a file lock or an absolute guarantee.

How does the macro keep Word and PDF files together?

It generates one filename stem and uses it for both the DOCX and the PDF. If PDF export fails after DOCX saving, the macro warns you to inspect the partial pair.

Will it also work with a mapped network drive or UNC folder?

An existing reachable UNC path or mapped drive can be used when the signed-in user has permission to save both file types. Network interruptions, folder access and Windows path limits may still cause a failure.

Can a blank Excel record ID or incorrectly mapped field cause repeated filenames?

Yes. If a batch script builds names from an empty or incorrect source field, many rows can use the same fallback such as Report. Inspect the Excel values and the filename-field mapping. Test with a fixed unique label to separate a data-mapping problem from a shared-folder race. The free macro on this page takes a manually entered label; it does not read Excel.

Does DocxForge Pro Factory guarantee concurrency-safe network writes?

Do not assume that from its naming settings. DocxForge Pro Factory supports configurable naming and Excel-to-Word/PDF batch production, but the screenshots do not establish atomic multi-user filename reservation. Confirm shared-folder requirements before using any tool concurrently.

Need a repeatable Excel-to-Word/PDF workflow instead of maintaining batch macros? DocxForge Pro includes Factory for Excel-driven batches, configurable output naming, template text/photo workflows and optional PDF export. Contractor is also included. Windows and Microsoft Word Desktop are required. Trial: 7 days free on the 3-month plan only. After the trial: $38 every 3 months unless canceled. Refund: Requests can be made within 14 calendar days after payment under the refund policy. Together with a full 7-day trial, this can provide up to 21 days from trial start to evaluate the software, but the period after trial is paid—not a 21-day free trial.