?
Solved

Edit HTML file using Visual Basic 6

Posted on 2005-04-21
6
Medium Priority
?
185 Views
Last Modified: 2013-11-25
Hi,

I have a MsWord document which I run a VB code to save it as HTML file.
I would like to add to it this code:
<script language = "javascript">
document.onmousedown=disableclick
function disablecklick(e) {
if( event.button==2 )
alert("Sorry");
return false;
}
</script>

Pls help.
Tks
0
Comment
Question by:2Angel
  • 5
6 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13836264
What about using the fso to convert it from word to a html file, then write that script into the text file using the FSO ( file system object ) and then changing the file extension from txt to html using the fso.

Not sure if this is what you are looking for ?

You may also need to add the other html lines ie

<HTML>
<BODY>

'with your script in here :)

</BODY>
</HTML>

Take a look here for using the FSO :

http://juicystudio.com/tutorial/vb/files.asp
0
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 200 total points
ID: 13836293
   Dim fso As New FileSystemObject
    Dim fsoStream As TextStream
    ' Create a text file, and return a reference to a TextStream
    Set fsoStream = fso.CreateTextFile("c:\htmlfile.txt", True) '<-- True is a boolen value indicating whether it
                                                                                                  ' should be over written if it exists
    ' Write to the file

fsoStream.WriteLine <script language = "javascript">
fsoStream.WriteLine document.onmousedown=disableclick
fsoStream.WriteLine function disablecklick(e) {
fsoStream.WriteLine if( event.button==2 )
fsoStream.WriteLine alert("Sorry");
fsoStream.WriteLine return false;
fsoStream.WriteLine }
fsoStream.WriteLine </script>


    fsoStream.Close
    Set fsoStream = Nothing
    Set fso = Nothing

'====================

Something like that, you may need double quote marks ie " around each item that you are writing ie

fsoStream.WriteLine "</script>" as apposed to fsoStream.WriteLine </script>

You would need to do this for each line that you write if it does not work as I posted above.

I hope this helps :)
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13836352
You can do something like this to rename the file :

Set fileSpec = fso.GetFile(fileName) '<-- filename must include the path of the file as well as the file(s) name
fileSpec.Name = "File_Name.html"

So if your file was located on the C drive then it would be as follows :

Set fileSpec = fso.GetFile(C:\File_Name.txt) '<-- filename must include the path of the file as well as the file(s) name
fileSpec.Name = "File_Name.html"

If that does not work then you could use the move file to basically delete the text file and rename it as html, hence creating the html file for you without leaving text files :)

Here is a url showing you how to use MoveFile  :

http://www.sloppycode.net/Reference/FSO/Ref-93.html
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13836369
I forgot to mention one thing, make sure you have a refernce to the Microsoft Scripting Runtime by going to Project --> References and checking the box next to it :) before you run it :)

Not sure if you knew this or not ?
0
 
LVL 2

Author Comment

by:2Angel
ID: 13842984
Thanks man!
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13843022
Your welcome ! Thanks for the points and grade ! I hope this helped you out ! You got it working now ?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question