Open As Readonly

S

SCSC

I'm trying to get my macro to open a file as Readonly, but
all I can do is get it to open a file. When I look at the
code that is created for opening, opening as readonly and
opening as copy, it all looks exactly the same.
 
S

SCSC

I should add to this that I am actually importing a TXT
file, so the code uses Workbooks.OpenText, not
Workbooks.Open

I see that if I use WorkBooks.Open, I can use
ReadOnly:=True, however this doesn't work for
Workbooks.OpenText
 
P

Pete McCosh

Ths code will do what you want, just replace the full file
name in the quotes. If you look at the VBA help for the
Open method, you'll see that you can add qualifiers to the
basic command to do pretty much anything you might want to
when opening a file.

workbooks.Open filename:="C:\amendments.xls",readonly:=true

Cheers, Pete
 
S

SCSC

Unfortunately, my followup message didn't get posted fast
enough, explaining that I'm importing a file, and
therefore using Workbooks.OpenText and not
Workbooks.Open.

Thanks to both of you, however, for your suggestions.
 
K

Kevin Beckham

I think you'll find that you have opened it readonly
because a text file opened by Excel can still be opened
using NotePad (for instance).
I think this is the case because the text is "loaded" into
an empty workbook.

If you were to open the file using the VBA code, then
Open "fileName.txt" For Input Access Read Shared As #1

Kevin Beckham
 

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