Open a non-read only excel file from word to be able to save it...

T

Tim

Hi Everybody,

I have written a bit of code to open an excel file from word and I wish to
work with it a bit (in particular, I wish to set a named range) from there.
When I finish working with it, I want to save the file. However, the manner
in which I open the file opens it as a Read-Only type so that I cannot save
the file with the same name. Here is what I have so far:

Dim excelApplication As Excel.Application

Set excelApplication = CreateObject("Excel.Application")
excelApplication.Visible = True
excelApplication.Application.Workbooks.Open (excelLocation)
excelApplication.Application.Dialogs(xlDialogDefineName).Show
' excelApplication.Application.ActiveWorkbook.Save <-- this is the "bad" part
excelApplication.Application.Quit

For now, assume excelLocation is a reference to a valid string.

Thank you all for your time,

Tim
 
R

Russ

Is the file properties read-only checkbox check marked?
If you try to load a file from a CD, it will be read-only by nature. In that
case copy the CD file to the hard drive, open the file's properties, and
uncheck read-only.
 
T

Tim

The file does not have the read-only checkbox check marked nor is the file
coming from a CD. It is stored in My Documents.

Thanks,

Tim
 
R

Russ

Another thing could be Windows OS putting a lock on a file that is still
open in another application. So you can't save it under the same name while
it is still be used by another application. Could that be what is happening
here?
 
T

Tim

Possibly. I tried to come up with a work-around by saving the file with a
different name, then deleting the old one and replacing it with the newly
saved one; however, I seem to not have permission to delete files using the
kill function. Could this be because I am not an administrator on my machine?

Thanks,

Tim
 
R

Russ

Definitely. Especially if you weren't the original creator of the file and
you are working on a machine with security policies set up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top