[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Open hidden txt files with VBA Open statement

Posted on 2007-10-05
4
Medium Priority
?
999 Views
Last Modified: 2012-05-05
Hello,

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?

Thanks,
J
0
Comment
Question by:jiiins2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:ahammar
ID: 20026617
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...

:-)
ah
0
 

Author Comment

by:jiiins2
ID: 20026633
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.
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 2000 total points
ID: 20026706
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
0
 

Author Comment

by:jiiins2
ID: 20026733
Thanks for the quick answer and sorry for my confused input/output question!

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Six Sigma Control Plans

834 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