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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Notepad, paste contents of listbox

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
0
0
GB
Can someone please help. I am trying to have a button to print the contents of a listbox, however to avoid any falling over due to networked printers, I am trying to call up Notepad, and paste the contents of the listbox (2 Columns) so the user can use the print command of notepad. Any ideas please, thanks
 
Hi,
Try the following:

Private Sub SaveList_Click()
str = ""
For i = 0 To List1.ListCount - 1
If str = "" Then
str = List1.List(i)
Else
str = str & vbCrLf & List1.List(i)
End If
Next i
intFile = FreeFile
Open "C:\test.txt" For Output As #intFile
Write #intFile, str
Close #intFile
MsgBox "Values saved to file C:\test.txt"
End Sub

This should save the values to a C:\text.txt


Hope it helps. Let me know what happens.
With regards,
PGK
 
... and once you have it saved, shell to notepad like this, to view and print the file:

Code:
Dim myRetVal
Dim strNotePad As String
strNotePad = "notepad " & "C:\text.txt" 
myRetVal = Shell(strNotePad, 1)
Jim Brown,
Johannesburg,
South Africa.
My time is GMT+2
 
Thanks Jim,
this is how we open a txt file in notepad.
how to open the files of other application,
like, how can we open a .jpg file in internet explorer..


Thanks for help..

lightss
 
Hi,
The syntax for the shell command is the same. You can open IE like

Shell "C;\Program Files\ie.exe C:\My Pictures\rain.jpg"

The basic syntax is
Shell "Name of exe to be opened with full path" & " file to be opened using that application"

Note: There must be a space between the name of the exe and the file to be opened. Hope it helps. Let me know what happens.
With regards,
PGK
 
Many thanks for the replies folks, nice to see other people join in/benefit. So it looks like saving data to a temp file, and then Notepad picking it up. Is there any control on fonts or is that only down to the user opening Notepad to do that? I thought there may be a way to pass data to the clipboard and then into Notepad, but the suggestions given look better. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top