Paste into opened notepad file

O

oOpsy

May i know how do i continue from my code below in order to allow me to
copy sheet3 cells A1:A42 into the opened file? I am able to call
notepad to open the .xml file but i need to paste the data from excel
into this opened file.Thanks!!

Private Sub CommandButton1_Click()
Shell "C:\Windows\Notepad.exe 'C:\project\fyp1.xml"

End Sub
 
C

Charlie

I don't know how to paste the clipboard contents into another spawned process
as you want. There may be a way to do it, but I would suggest reading about
opening/closing/reading/writing to text files in VB help.

You don't say where you want to paste the cell contents in the file. Below
are two examples. The first one appends the cells to the end of the file.
The second one appends each cell to the end of each line of the text file,
assuming there is one line for each cell.

I did not test these examples, they are simply to give you an idea how to
get started.

' Method 1 - append to end of file

Dim Cell As Range

Open "C:\project\fyp1.xml" For Append As #1

For Each Cell In Sheets("Sheet3").Range("A1:A42")
Print #1, Cell.Text
Next Cell

Close #1

' Method 2 - append to end of each line of file

Dim Rec As String
Dim nRec As Long

Open "C:\project\fyp1.xml" For Input As #1
Open "C:\project\fyp1_NEW.xml" For Output As #2

Do While Not EOF(1)
Line Input #1, Rec
nRec = nRec + 1
Print #1, Rec & Sheets("Sheet3").Cells(nRec, 1).Text
Loop

Close #1
Close #2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top