Tom McDonald
Tom McDonald

Reputation: 1892

saveAs UNC path fails but mapped path works

I have some Excel VBA code below that saves an Excel file. It works if I save using as a mapped drive, but fails if I use a UNC path. I double-checked the UNC path and it is correct.

I get: "Run-time error '1004' method saveAs of object _Workbook failed"

mappedFileName = "x:\myFile.xlsm"
uncPathFileName = "\\fileServer01\pathPart\myFile1.xlsm"
ActiveWorkbook.SaveAs mappedFileName, FileFormat:=52 
ActiveWorkbook.SaveAs uncPathFileName, FileFormat:=52 

Upvotes: 1

Views: 1776

Answers (2)

MatthewD
MatthewD

Reputation: 6761

Try using the Filename parameter ActiveWorkbook.SaveAs Filename:=uncPathFileName, FileFormat:=52

The drive may be mapped to a share... So you might no have the permissions through the UNC path...

If ActiveWorkbook.SaveAs Filename:="\\fileServer01\pathPart\myFile1.xlsm", FileFormat:=52 then there may be an access issue.

The only other thing i can think of is trying the current format , FileFormat:=CurrentFormat

Upvotes: 1

Tom McDonald
Tom McDonald

Reputation: 1892

OK, my bad. I upon triple checking I discovered the UNC path-part was misspelled.

Upvotes: 0

Related Questions