Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Excel text file as readonly

Status
Not open for further replies.

grannyM

Programmer
Nov 26, 2002
39
US
I have a macro that opens a daily excel fixed length text file using VBA. This file is received from off-site. It is used by several users and if it is in use, the macro gives the alert box "File is being modified by another user. Open as read-only." I'm trying to bypass this alert box by automatically opening the file as read-only, as it is not feasible to go in each day and manually make the file read-only. However, I have not been able to find where you can open and parse out a text file as read-only. I've tried recording as I open the file, and when I do it manually, it does open as read-only, but the code stays the same as below, and when I execute it, it does not open the file as read-only.

Code:
Workbooks.OpenText FileName:=PSFileName$, Origin:= xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(15, 2), Array(26, 2), Array(41, 1), Array(58, 1), Array(73, 1), Array(86, 1))
Code:

Does anyone know how to open this as read only or have another way of bypassing this alert box? Thanks for any help you can give.

granny
 
Have you tried this ?
Application.DisplayAlerts = False

Hope This Help
PH.
 
GrannyM,

Just ensure that when you've executed your code you add
Code:
Application.DisplayAlerts = True
to avoid missing any important future messages.

Hope this helps.


Leigh Moore
Solutions 4 MS Office Ltd
 
yes, I did remember to turn the DisplayAlerts back to true, but thanks for the tip because it would have been easy to forget.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top