Open hidden txt files with VBA Open statement

Posted on 2007-10-05
Last Modified: 2012-05-05

in an Excel 2003 vba function I'm trying to open a normal txt file like this:
Open filename for input as #1

It works fine until I hide the file (using explorer's file properties). When the file is hidden, the function can't find it anymore... what am I missing? How can I retrieve it when is hidden?

Question by:jiiins2
    LVL 23

    Expert Comment

    Is there anything special about your function that you haven't mentioned?  I just tried it and the code that you are using will open and read a text file just fine in a sub procedure, even if it is hidden with explorer's file properties...
    Are you sure you didn't accidently change the name or location of the file in Explorer or your code?
    Is there anything else that you can tell us...maybe paste your problem code here for us to see...


    Author Comment

    Here is the code:

    flFees = ThisWorkbook.Path & "\fees.txt"
    Open flFees For Output As #1                    <- here I get run-time error 75

    If I unhide fees.txt it works fine.
    LVL 32

    Accepted Solution

    you had shown INPUT #1 in your Q.

    Yes OUTPUT fails with Path/File Access error when file exists and is hidden.
    resolution is easy enough....

    Sub SendOut()
        Dim flpath As String
        flpath = "c:\work\ee\test1.txt"
        If GetAttr(flpath) And vbHidden Then          'check for hidden
            SetAttr flpath, GetAttr(flpath) - vbHidden
        End If
        Open flpath For Output As #1
            Print #1, "test2"
        Close #1
        SetAttr flpath, GetAttr(flpath) Or vbHidden     'set to hidden
    End Sub

    Author Comment

    Thanks for the quick answer and sorry for my confused input/output question!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
    This is an explanation of a simple data model to help parse a JSON feed
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
    This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now