need to copy few cells into notepad

madtalent

New Member
Joined
Jul 26, 2011
Messages
6
Good day, I'm new here, I'd like to ask if there is a way to copy certain cells into a notepad. lets say I'd like to copy the texts in cell A1 to notepad.txt inside the notepad written there is

notes in notepad. *insert text from cell A1 here* end of text.

is it possible? Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try Code below

Code:
Sub test()
    'The range that contains the values
    Range("A1").Copy
    'Start Notepad And let it recieve focus
    Shell "notepad.exe", vbNormalFocus
    'Send the keys CTRL+V To Notepad (i.e the window that has focus)
    SendKeys "^V"
End Sub

Biz
 
Upvote 0
In Excel file which has data in cell A1 that you want to transfer to notepad.

1) Press Alt+F11
2)Insert->Module
3) Copy & paste vba code I have provided you
4)Press ALlt+F8 and click macro and it runs.

Biz
 
Upvote 0
great it worked. thanks. btw what if I wanted to paste the content of A1 cell to an already made .txt file named notepad. what will be the changes must be made to make it possible? thanks
 
Upvote 0
Try code below.

Code:
Sub test()
    'The range that contains the values
    Range("A1").Copy
    'Start Notepad And let it recieve focus
     Shell "notepad.exe c:\Temp\Test.txt", vbNormalFocus
    'Send the keys CTRL+V To Notepad (i.e the window that has focus)
    SendKeys "^V"
End Sub


Please note notepad default file and folder I have created is
c:\Temp\Test.txt change it to suit your situation.

Biz
 
Upvote 0
yes it worked. but it pasted on the first line inside the test.txt. what if I wanted to replace a certain word inside the notepad with the value of A1 cell? or paste the value of A1 in a specific location/line inside the test.txt.

like this in test.txt: can I replace the word 'texts' with the value of A1
heading

body of texts
or

paste the value of A1 in a specific location/line inside the test.txt
heading

body of texts
>paste here the value of A1

would these be possible or one of them would be possible? Thanks. :)
 
Upvote 0
Sorry not sure how to do that. There would be someone in forum who could help?

Biz
 
Upvote 0
You can use File Scripting as below to append to an existing text file

ie to append the value in A1 to a text fille with path "C:\temp\Test.txt"

hth

Dave

Code:
Const ForAppending = 8
Sub AppendText()
Dim objFSO
Dim objFIle
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFIle = objFSO.OpenTextFile("C:\temp\Test.txt", ForAppending)
objFIle.WriteLine [a1].Value
objFIle.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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