Open As Readonly

  • Thread starter Thread starter SCSC
  • Start date Start date
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.
 
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
 
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
 
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.
 
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
 
Back
Top