Displaying Word.htm in InnerHTML

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jwestan
Posts: 48
Last visit: Mon May 04, 2015 5:59 am

Displaying Word.htm in InnerHTML

Post by jwestan »

I am trying to get a Word document that was saved as a .htm file into a DataArea.InnHTML span and I keep getting an Unspecified error. I would like to keep this as a file as this is instructions for using the HTA and would like to only update a file and not have to modify the HTA but keep the formating in the document.

This is what I am using to read the file but I suspect that the extra HTML is causing the error.

Code: Select all

Const ForReading = 1
	
Dim instrFileLoc : instrFileLoc = "C:Test_2.htm"
Dim fso1 : Set fso1 = CreateObject("Scripting.FileSystemObject")
Dim f : Set f = fso1.OpenTextFile(instrFileLoc,ForReading)
Dim strInstructions : strInstructions = f.ReadAll
f.Close
	
Sub window_onLoad
CheckForNewHTA 'Checks for new HTA on the O:Drive
 window.resizeTo 1200,800
  AppName.InnerHTML = strAppName
  AppVersion.InnerHTML = strAppVer
  'TextBox1.Focus
  AppDate.InnerHTML = strDate
  DataArea.InnerHTML = strInstructions
End Sub
	

Anyone have any ideas or examples?
User avatar
jwestan
Posts: 48
Last visit: Mon May 04, 2015 5:59 am

Displaying Word.htm in InnerHTML

Post by jwestan »

I am trying to get a Word document that was saved as a .htm file into a DataArea.InnHTML span and I keep getting an Unspecified error. I would like to keep this as a file as this is instructions for using the HTA and would like to only update a file and not have to modify the HTA but keep the formating in the document.

This is what I am using to read the file but I suspect that the extra HTML is causing the error.

Code: Select all

Const ForReading = 1
	
Dim instrFileLoc : instrFileLoc = "C:Test_2.htm"
Dim fso1 : Set fso1 = CreateObject("Scripting.FileSystemObject")
Dim f : Set f = fso1.OpenTextFile(instrFileLoc,ForReading)
Dim strInstructions : strInstructions = f.ReadAll
f.Close
	
Sub window_onLoad
CheckForNewHTA 'Checks for new HTA on the O:Drive
 window.resizeTo 1200,800
  AppName.InnerHTML = strAppName
  AppVersion.InnerHTML = strAppVer
  'TextBox1.Focus
  AppDate.InnerHTML = strDate
  DataArea.InnerHTML = strInstructions
End Sub
	

Anyone have any ideas or examples?
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Displaying Word.htm in InnerHTML

Post by rasimmer »

I would suggest using a iFrame vs writing the data to a SPAN, otherwise you're placing another entire HTML document inside of another which would mess your tags all up. Some of the other members might tell me I'm crazy, but it's what I would try.
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Displaying Word.htm in InnerHTML

Post by rasimmer »

So, how does that work JVierra? All of the HTML tags duplicated in the middle of an existing document....no issue?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Displaying Word.htm in InnerHTML

Post by jvierra »

Here is the easiest wat to do this. I used PoSH because it is faster and easier to demo this with. VBS works the same way.

Code: Select all

	
$ie=new-object -com internetexplorere.application
$ie.Navigate("c:testtest.htm")
$ie.Document.body.innerHTML
	
# the following is extracted
	

Hello World 

This will NOT work with documents loaded from the Internet or other untrusted sources. It will work with all domain trusted sources.
User avatar
jwestan
Posts: 48
Last visit: Mon May 04, 2015 5:59 am

Displaying Word.htm in InnerHTML

Post by jwestan »

So would it look something like this for vbscript in a HTA? I am still getting an Unspecified Error.

Code: Select all

	Sub window_onLoad
	  Dim ie : Set ie = CreateObject("InternetExplorer.Application") ie.Navigate("C:Test_3.htm") Dim ieInner : ieInner = ie.Document.body.InnerHTML  DataArea.InnerHTML = ieInner
	end sub
	[/code
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Displaying Word.htm in InnerHTML

Post by jvierra »

I like this myself:

Code: Select all

	
    With CreateObject("InternetExplorer.Application")
        .Navigate("C:testTest.htm")
        DataArea.InnerHTML = .Document.body.InnerHTML
    End With

No need for all those variabes for somethng that is a throw-away.
This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked