VBA Permission Denied Error 70 When trying to create text file
Posted on 2013-11-05
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?
' 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]