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

How to open Notepad in VBA

Status
Not open for further replies.

Lavey

IS-IT--Management
Jun 1, 2001
115
DE
Hi Guys,

I need to be able to open notepad and dump in some values at the click of a command button.

I have the code sorted to extract the values I want from a list box, just need to know if its possible to open notepad and dump these in :)

THx in advance for any info


siglavey.jpg
 
Hi,
The code below is uses a command button to save the current list values to a file and loads it from the file at Form Load.

Private Sub Form_Load()
On Error GoTo errHandler
intFile = FreeFile
Open "C:\test.txt" For Input As intFile
Input #intFile, str
Close #intFile
lastPos = 1
currPos = 1
If InStr(1, str, &quot;,&quot;, vbBinaryCompare) <> 0 Then
Do While InStr(lastPos, str, &quot;,&quot;, vbBinaryCompare) <> 0
currPos = InStr(lastPos, str, &quot;,&quot;, vbBinaryCompare)
List1.AddItem Mid(str, lastPos, currPos - lastPos)
lastPos = currPos + 1
Loop
List1.AddItem Mid(str, lastPos, Len(str) - (lastPos - 1))
Else
List1.AddItem str
End If
Form_Exit:
Exit Sub
errHandler:
Select Case Err.Number
Case 53
Resume Form_Exit
Case Else
MsgBox &quot;Unexpected Error&quot; & vbCrLf & Err.Number & vbCrLf & Err.Description, , &quot;ERROR&quot;
End Select
End Sub


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

Hope it helps. Let me know what happens.
With regards,
PGK
Hope it helps. Let me know what happens.
With regards,
PGK
 
That is very cool, is there a way of having the text file open after write, instead of msgbox?
This is becuase the user can then copy all the values (inc html formatting)and paste directly to a bulletin board.
siglavey.jpg
 
oh. yeah.. thx for super prompt reply :)
siglavey.jpg
 
Hi,

You can get an idea as to how to write to and read from a file. Modify according to your needs. Hope it helps. Let me know what happens.
With regards,
PGK
 
Just found this , does the job ......

Shell &quot;NOTEPAD &quot; & &quot;C:\test.txt&quot;, vbNormalFocus

siglavey.jpg
 
Lavey, you should put your code into a FAQ. I think a lot of pepole would find it V. useful.

aexley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top