There is a way -that I can think of- to do that but it's really painful. The same way Teemu mentioned. But If you insist on a single hta file, here's your code:
<html>
<head>
<title>Main HTA</title>
<HTA:APPLICATION
SCROLL="no"
INNERBORDER="no"
/>
</head>
<body>
This is the main HTA <br /><br />
<input type="button" value="open sub hta" onclick="runSubHTA(subhta)" />
<script type="text/javascript">
// path to the new (sub) hta file
var subhta = "subhta.hta";
// function to create and launch the sub hta file
function runSubHTA(path) {
// creating the new hta file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var sub = fso.CreateTextFile(subhta, true);
// writing to the created hta file
sub.WriteLine("<title>Sub HTA<\/title>");
sub.WriteLine("Welcome to the sub HTA <br />");
// this code will run on the sub hta before exit
// and it'll delete the sub hta file, meaning itself
sub.WriteLine('<script type="text/javascript">');
sub.WriteLine('var subhta = "subhta.hta";');
sub.WriteLine('window.onbeforeunload = function() {');
sub.WriteLine('var fso = new ActiveXObject("Scripting.FileSystemObject");');
sub.WriteLine('var sub = fso.DeleteFile(subhta, 1);');
sub.WriteLine('}<\/script>');
// closing the connection to the file, we're done writing
sub.Close();
// launching the sub hta file
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run(path, 1, false);
}
</script>
</body>
</html>
Coding 2 separate hta files would be much easier. This way you have to embed your sub hta code line by line. But there might be a better way to do it. Like writing the whole page in a single line with line-breaks and indenting. I haven't tried something like this before so I can't help on this. But if you find a way to do it, do share.