4

If Excel_Default_Path is set to C:\ProjectOutput the following code works perfectly. But if Excel_Default_Path is set to C:\Users\Me\ProjectOutput it fails with a 1004 error. Also, the appExcel object has no problem at all reading from that same directory in either case.

The DefaultOutputFilename is set to AA1FS-7_VE8GUS_ED.xls and fmt is getting the correct type. Just putting it into the User directory is a problem though.

A little more info. If I quit out of the VB app and select the open Excel app. I can directly save the modified workbook to C:\Users\Me\ProjectOutput with no problem at all.

Also, this error occurs on my machine, as well as another machine. The other machine Excel_Default_Path is set to C:\Users\JSS\ProjectOutput

    Dim fmt As Excel.XlFileFormat = GetExcelFileFormatForExtension(fi)
    appExcel.ActiveWorkbook.SaveAs(CStr(Excel_Default_Path & "\" & DefaultOutputFileName), fmt)
user2021539
  • 949
  • 3
  • 14
  • 31
  • 3
    Sounds like the application doesn't have write privileges to your folder. Check that first. – Mr Lister Jun 26 '16 at 19:37
  • Not sure what you're asking here. I am logged in as me, with administrator privs. The Security properties of the C:\Users\Me\ProjectOutput are Full Control for all users. This is running on Windows 7 Pro 64. – user2021539 Jun 26 '16 at 20:35
  • 1
    Please [edit] your question title to something meaningful. *Why does this fail* contains zero relevant information, and that it's a VB question is clear from the vb.net tag you added. Your title should give information about the problem you're having or question you're asking in a way that will convey information to a future reader here who finds it in a search result. – Ken White Jun 26 '16 at 23:38
  • An executable does not necessarily have the same privs you have. Try "Run as administrator" to see if that makes a difference. It's not a web application, is it? – Mr Lister Jun 27 '16 at 08:58
  • It's not a web app. I ran it as Administrator, but no change. – user2021539 Jun 27 '16 at 11:32
  • Can you go to that folder and create a file by yourself ? Like right-click->New->Text Document ? Sometimes user folders are locked weird ways, even for the admin. – Martin Verjans Jun 29 '16 at 14:33
  • Yes. Creating a new text file with the right-click in the C:\Users\Me\ProjectOutput has no problem at all. – user2021539 Jun 29 '16 at 15:10
  • See this link - it may be your solution - http://stackoverflow.com/questions/28967762/getting-method-saveas-of-object-workbook-failed-error-while-trying-to-save-an – David Wilson Jun 30 '16 at 17:09

1 Answers1

1

I have solved the problem. The Excel_Default_Path actually had a trailing "\" at the end. So that caused the 1004 error. Removing the \ from the variable fixed it.

user2021539
  • 949
  • 3
  • 14
  • 31