Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Notepad

Status
Not open for further replies.

PFairhurst

Programmer
Jul 30, 2002
18
GB
I want to be able to put information into notepad so I can print it, but I am unsure on how to connect to it! Thank you
Pete
 
Do you actually want to open notepad or do you just want to print the text file? If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
Notepad isn't very much into COM and stuff...
I think you should launch it with a Shell command and then send it keystrokes with SendKeys.
 
This should get you started. Note the code assumes you have a default printer for the computer and you will need to change the path for NotePad as well as the text file. Let me know if this helps.

Drop this code in a command button click event

Private Sub Command1_Click()
Dim iFF As Long
Dim ans As VbMsgBoxResult
Dim strData As String

iFF = FreeFile
Open "C:\TestTextFile.txt" For Append As #iFF 'Write to a text file
Print #iFF, "First Line"
Print #iFF, "Second Line"
Print #iFF, "Third Line"
Close #iFF

ans = MsgBox("Do you wish to print?", vbYesNo, "Choose an Option")
If ans = vbYes Then 'Print
Open "C:\TestTextFile.txt" For Input Access Read As #iFF
Do While Not EOF(iFF)
Input #iFF, strData
Printer.Print strData
Loop
Close #iFF
Else 'Open NotePad
Shell "E:\WINNT\system32\notepad.exe C:\TestTextFile.txt", vbNormalFocus
End If
End Sub If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
You can run notepad.exe by this code too.

set ws=CreateObject("WScript.Shell")
wscr.run("notepad.exe")

Also if you want to open a text file in notepad you can use this code:

set ws=CreateObject("WScript.Shell")
wscr=run("c:\my documents\test.txt")


I hope this will be usefull for you.
BehnamPro
 
When I took my 2nd sem of VB in college, we made our own notepad program with a text box and form. I would think that would be the easiest. You can always save it as a text file too if you want it saved.
 
you can open notepad.exe by this code too:
set ws=CreateObject("Scripting.FileSystemObject")
ws.run("notepad.exe")
That code opens a blank notepad document,so if you want to open a text file in notepad use this code:
set ws=CreateObject("Scripting.FileSystemObject")
ws.run("c:\test.txt")
that code opens test.txt in notepad. Behnam2204@yahoo.com
BehnamPro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top