If you can't explain it simply,
you don't understand it well enough.
-Albert Einstein
 
Home   News   Courses   Tips   Templates   Forums   Help   Order   Contact   Logon  
 
NEW: Excel Expert 11 - Learn XLOOKUP    dismiss
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
HTA

Expert - Write File

How to write to a File

Add a TextArea to your HTA.

	<textarea name="TextFile" id="TextFile" rows="20" cols="50">
	</textarea>
	

Add a button to write to the file.

	<input type="button" value="Submit" onclick="Submitarea">
    

Then add some code.

	Const ForWriting = 2
	
	Dim objFSO, objFile, strFileName
	strFileName = "textfile.txt"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
	
	Set objFile = objFSO.OpenTextFile(strFileName, 2, true)
	Set objShell = CreateObject("WScript.Shell")
	
	Sub Submitarea
		sTxtarea = TextFile.Value
		oFIle.Write sTxtarea & vbCRLF
		MsgBox "Your text has been added to " & strFileName, 64, "Textarea Input"
	End Sub
	

It would then be handy to open that File. Add another button to do this.

	<input type="button" value="Open" onclick="OpenTxtArea">
	
	Sub OpenTxtArea
		ShellRun = objShell.Run ("%comspec% /c Start Notepad " & strFileName, 0, 1)
    End Sub 
	

WriteFile HTA


Sample Files
.hta


Previous Lesson: Expert Level 3 | Next Lesson:

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search The Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

YouTube Channel    LinkedIn

Blog RSS Feed