Hello.
The first part of my code works fine. I'm getting a "permission denied" error for the second part of the code starting at "Set stream". This code works fine if my filepath is the desktop. I have permission for the Q drive/folder. Any help is appreicated.
Thank you!
The first part of my code works fine. I'm getting a "permission denied" error for the second part of the code starting at "Set stream". This code works fine if my filepath is the desktop. I have permission for the Q drive/folder. Any help is appreicated.
Thank you!
Code:
'THIS CODE CREATES A NEW TXT FILE
Sub createANewtextFile()
Dim sFilePath As String
Dim fileNumber As Integer
sFilePath = "Q:\xxxx\yyyyy\ExcelTextTEST.txt"
' Assign a unique file numner
fileNumber = FreeFile
Open sFilePath For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=fileNumber]#fileNumber[/URL]
End Sub
'THIS CODE WORKS TO COPY FROM EXCEL AND PASTE TEXT INTO A TXT FILE
Sub COPY_FROM_EXCEL_AND_PASTE_TEXT_INTO_A_TXT_FILE()
Range("A1").Select
Dim FilePath As String
Dim CellData As String
Dim LastCol As Long
Dim LastRow As Long
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim stream As TextStream
LastCol = ActiveSheet.UsedRange.Columns.Count
LastRow = ActiveSheet.UsedRange.Rows.Count
' Create a TextStream.
Set stream = fso.OpenTextFile("Q:\xxxx\yyyyy\ExcelTextTEST.txt", ForWriting, True)
CellData = ""
For i = 1 To LastRow
For j = 1 To LastCol
CellData = (ActiveCell(i, j).Text)
stream.WriteLine CellData
Next j
Next i
stream.Close
End Sub