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

MrPink1986

Active Member
Joined
May 1, 2012
Messages
252
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
Code:
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

Code:
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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,223,701
Messages
6,173,920
Members
452,539
Latest member
deeme

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top