DDEInitiate with Notepad

K

Kevin

I am trying to automate the process of copying
information out of Excel and pasting it into Notepad.
Saving the information from Excel as a text file does not
work for the task I am trying to accomplish. Below is the
code I created to do this procedure. My thought process
was to use the Shell function to open Notepad and the
specific file and then the DDEInitiate to open the
channel to the file. But at the DDEInitiate line I get
the question box "Remote data not accessible. Start
application Notepad.exe?", I click Yes and then I
get "Run-time Error '13'; Type mis-match" and the
procedure stops. I then have 2 windows of the GL.txt file
open. Any help would be greatly appreciated.

Sub Test()
Sheets("Download").Select
Range("A2:A55").Select
Selection.copy
Notepd = Shell("C:\Windows\System32\Notepad.exe
C:\GL.txt", 1)
Channelnumber = Application.DDEInitiate
("Notepad", "C:\GL.txt")
Application.DDEExecute Channelnumber, "[EDITPASTE]"

End Sub
 
K

keepitcool

This would be how i'd do it.

You can delete the ^end if you're working with an empty
file.

Sub Test()
ActiveSheet.Range("A2:A55").Copy
If Shell("Notepad.exe 'c:\gl.txt'", 1) > 0 Then
DoEvents
SendKeys "^{END}^v^s%{F4}", True
Else
MsgBox "Cant open notepad"
End If
Application.CutCopyMode = False
End Sub



keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
T

Tom Ogilvy

What makes you think notepad supports DDE?

Hard to believe that writing a text file can't accomplish what you want.
 
G

Guest

Tom,

When I save as a text file it add quotation marks to the
beginning and end of each line, no matter what format I
save it as. To use the following as an example:

I need to copy "028001002399 GLTransfer 120.00

and I get """028001002399 GLTransfer 120.00"

This will not allow for the file to be uploaded into our
GL system.



-----Original Message-----
What makes you think notepad supports DDE?

Hard to believe that writing a text file can't accomplish what you want.

--
Regards,
Tom Ogilvy

Kevin said:
I am trying to automate the process of copying
information out of Excel and pasting it into Notepad.
Saving the information from Excel as a text file does not
work for the task I am trying to accomplish. Below is the
code I created to do this procedure. My thought process
was to use the Shell function to open Notepad and the
specific file and then the DDEInitiate to open the
channel to the file. But at the DDEInitiate line I get
the question box "Remote data not accessible. Start
application Notepad.exe?", I click Yes and then I
get "Run-time Error '13'; Type mis-match" and the
procedure stops. I then have 2 windows of the GL.txt file
open. Any help would be greatly appreciated.

Sub Test()
Sheets("Download").Select
Range("A2:A55").Select
Selection.copy
Notepd = Shell("C:\Windows\System32\Notepad.exe
C:\GL.txt", 1)
Channelnumber = Application.DDEInitiate
("Notepad", "C:\GL.txt")
Application.DDEExecute Channelnumber, "[EDITPASTE]"

End Sub


.
 
T

Tom Ogilvy

If you use low level fileio, you can format it however you desire:

http://support.microsoft.com/support/excel/content/fileio/fileio.asp
File Access with Visual Basic® for Applications

Build a single string per line that you want to write, formatted the way you
want, then write it out a line at a time - would be one approach.


--
Regards,
Tom Ogilvy

Tom,

When I save as a text file it add quotation marks to the
beginning and end of each line, no matter what format I
save it as. To use the following as an example:

I need to copy "028001002399 GLTransfer 120.00

and I get """028001002399 GLTransfer 120.00"

This will not allow for the file to be uploaded into our
GL system.



-----Original Message-----
What makes you think notepad supports DDE?

Hard to believe that writing a text file can't accomplish what you want.

--
Regards,
Tom Ogilvy

Kevin said:
I am trying to automate the process of copying
information out of Excel and pasting it into Notepad.
Saving the information from Excel as a text file does not
work for the task I am trying to accomplish. Below is the
code I created to do this procedure. My thought process
was to use the Shell function to open Notepad and the
specific file and then the DDEInitiate to open the
channel to the file. But at the DDEInitiate line I get
the question box "Remote data not accessible. Start
application Notepad.exe?", I click Yes and then I
get "Run-time Error '13'; Type mis-match" and the
procedure stops. I then have 2 windows of the GL.txt file
open. Any help would be greatly appreciated.

Sub Test()
Sheets("Download").Select
Range("A2:A55").Select
Selection.copy
Notepd = Shell("C:\Windows\System32\Notepad.exe
C:\GL.txt", 1)
Channelnumber = Application.DDEInitiate
("Notepad", "C:\GL.txt")
Application.DDEExecute Channelnumber, "[EDITPASTE]"

End Sub


.
 

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