How to Use a UNC Network Path in an Excel VBA Macro
Question details
The user needs to know the correct path format to save a PDF file to a shared network folder using an Excel VBA macro.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating the saving of a PDF file to a remote shared network folder via an Excel VBA macro without relying on mapped drive letters.
- Observed behavior
- The user requires the exact UNC path syntax, beginning with a computer or server name, to correctly reference the network destination in the VBA code.
Verify the exact network server name and ensure you have sufficient read and write permissions for the target shared network folder.
Format and Apply the UNC Path in Your VBA Code
Use the Universal Naming Convention (UNC) syntax to directly target a network folder in your VBA macro.
A UNC path allows you to access shared network folders directly without relying on a mapped drive letter, which is highly beneficial when sharing macros across different users. It strictly begins with two backslashes followed by the server name, the share name, and any subfolders.
Determine your server and folder name. The format must be \\ServerName\ShareName\Subfolder\. For example, \\MyPC\Documents\.
In Excel, press ALT + F11 to open the Visual Basic for Applications (VBA) editor and locate the macro script you wish to modify.
Assign the UNC path to your filename string, ensuring you keep the trailing backslash. For example: Dim FilePath As String FilePath = "\\MyPC\Documents\".
Use this path in the Filename argument when saving your PDF. Example: ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FilePath & ActiveWorkbook.Name & ".pdf".

Run Macros and Save to Network Paths with WPS Office
WPS Office offers native support for VBA macros, allowing you to seamlessly run scripts that export documents as PDFs to UNC network paths, matching the experience of Microsoft Excel.
- 1. Open your macro-enabled workbook: Launch WPS Spreadsheet and open your existing .xlsm file.
- 2. Access the Macro Editor: Navigate to the Tools tab and click on Macro, or press ALT + F11 to open the WPS Macro Editor.
- 3. Implement the UNC Path: Type or paste your VBA code utilizing the UNC path format (e.g., \\ServerName\ShareName\).
- 4. Execute the Code: Click the Run button or press F5 to execute the ExportAsFixedFormat command and successfully save your PDF to the network folder.

Frequently Asked Questions
Why is my VBA macro failing with a 'Path not found' error when using a UNC path?
This usually occurs if you lack write permissions to the network folder, if the server is offline, or if there is a typo in the path string. Double-check that your path begins with exactly two backslashes (\\) and that you can access the location manually via Windows File Explorer.
Can I use mapped drive letters instead of UNC paths in VBA?
Yes, you can use a mapped drive (like Z:\Documents\). However, UNC paths (\\Server\Documents\) are strongly recommended for shared macros because other users might not have the same drive letters mapped on their computers.
How do I add a specific file extension when saving via a UNC path?
When appending the file name to your UNC path string, simply concatenate the extension string at the very end. For example: Filename:="\\MyPC\Documents\" & "MonthlyReport" & ".pdf".




