SaveAs CSV File Error: Access is Denied

Hi all!

I have been working on writing a macro to analyze large batches of microscopy images and it has been working for the most part. The part where I’m having issues is when I try to save my results window as a CSV file. When the code tries to saveAs a CSV file, I get an error stating that “Access is Denied”, and it will not save my results. I was wondering if anyone here could help me solve that issue. Thanks so much!

Is there any chance you are saving the CSV with the same name as an existing CSV file that is already open in, say, Excel or another program?

Hmm, it shouldn’t be since I made it save like this:

saveAs(“Results” + subj, excel);

so that every time it saves, it will be according to the subject number, and the variable “excel” is just the specified file destination.

Right, the error is usually when you already have that file open. You can’t overwrite it while it is open.

If that is not the case, would need more information about where you are saving to (network drive? mydocuments but on a network drive due to active directory settings?) and how many different places you have tried to save to that have failed.

Also, the script itself.

Ah sorry I didn’t understand what you meant at first. But no, the file isn’t open. I’m assuming that if I specify a destination, that it will automatically create a new csv file, or do I have to first create the csv file, then have it as to that file? And no I haven’t tried saving it to another destination yet but I’ll try that now. It is saved to mydocuments on my PC.

It also looks like your format is not right.
It should be saveAs(“WhatYouWantToSave”, file location and potentially name)
so saveAs("Results", dir+filename+".csv")
For example, this is from one of my script loops:
image

Ah ok, I’ll try that and see what happens.

Ok so that worked! Now I have another problem where the ROI Manager says that more than 1 item must be selected :frowning: but I think I should be able to figure that out. Thank you so much for the help!

1 Like