[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBA Permission Denied Error 70 When trying to create text file

Posted on 2013-11-05
2
Medium Priority
?
4,684 Views
Last Modified: 2013-11-05
Hello,

I have a small Excel 2007 app that creates a text file based on the rows.  It worked fine until I re-imaged my computer (Windows 7 Pro).  It now gives an error at the line:

   Set stream = fso.CreateTextFile(fName, False)

I'm guessing this is related to the Windows 7 permissions for the folder but I checked them and I am an administrator with full permissions.  I recall windows 7 was fickle about allowing writing to certain folders but I am trying to write to my documents, desktop, etc.  where the folders show I have access in windows permission dialogue.  I would like to pass this app along to others who may not have administrator rights as well.  Is there a work around for the permissions problem or is there another problem that you see?


Thanks

Zip

Sub generateKML()
' GenerateKML Macro
' Original Macro recorded 26/09/2006 by simon_a
' Modified by KOD Oct 4, 2007
' Set file path
   ' On Error Resume Next
   
    Dim fso As New FileSystemObject
' Declare a TextStream.
    Dim stream As TextStream
    Dim fName As String
    fName = [KML_Details!C2]
' Create a TextStream.
    Set stream = fso.CreateTextFile(fName, False)  <--------ERROR 70 HERE
   
 'Write header to file
        stream.WriteLine [KML_Details!C5] & [KML_Details!C3] & [KML_Details!C6]
0
Comment
Question by:zipnotic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 1140 total points
ID: 39624756
Hi,

Running your code in a Microsoft Windows 7 Enterprise 6.1.7601 Service Pack 1 Build 7601/Microsoft Excel 2010/14.0.6129.5000 (32-bit) environment poses no problems for me.

I specified a filename (without a path) in cell [C2] & the file was saved in the "Default file location".

With a value of path\filename the file was created as expected.

However, if I specified "C:\test.txt" (without quotes), for instance, then writing to the root directory of the C: drive is restricted, & I do see Error #70 ("Permission Denied"), as you did.

Could it be that the rebuilt operating system you are using has an Anti-Virus application that is stopping the creation of files within folders that you would expect to have access to?

BFN,

fp.
0
 

Author Closing Comment

by:zipnotic
ID: 39624828
I neglected to add the actual file name onto the path.  

That was easy.  You put me on the right path.

Thanks for the quick response!

Zip
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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