# Copy data from excel and paste into Notepad/Notepad++



## MrPink1986 (Apr 16, 2019)

Hi there,

I have data in column A on a sheet named "IM Sample". 
i want to take the data here and copy it into a new notepad/notepad++ file. I then wish to save the file in a specified folder and a specified name. 

Location C:\Users\XXXXX\Documents\
File Name - test_File.req

Is this possible?

I have attempted two scripts to run this - the one below creates the file on my C drive however it does not copy the data from the excel file

```
Sub Create_Text()Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer


myFile = Application.DefaultFilePath & "\test_File.req"
Set rng = Selection
Open myFile For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
For i = 1 To rng.Rows.Count
    For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
    Write [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , cellValue
Else
    Write [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , cellValue,
End If


    Next j
Next i


Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]
```

This one gives me a error "Invalid or Unqualified reference


```
Sub CopySelectionNotepad()Dim WS As Worksheet, CheminDest As String, fNAME As String


On Error Resume Next
CheminDest = "C:\XXX\XXX\" & Sheets("Workings").Range("D1")
MkDir CheminDest
CheminDest = CheminDest & "\"
MkDir CheminDest
On Error GoTo 0
fNAME = "IM.Sample"


With Application
Selection.Copy
Shell "Notepad.exe", 3
SendKeys "^v"
VBA.AppActivate .Caption
.CutCopyMode = False
End With
        
.SaveAs Filename:=CheminDest & fNAME & ".req"
.Close False
End With
        
    MsgBox "Text file has been saved ", vbInformation, "Data backup"


End Sub
```


----------

