Edit HTML file using Visual Basic 6

Posted on 2005-04-21
Last Modified: 2013-11-25

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">
function disablecklick(e) {
if( event.button==2 )
return false;

Pls help.
Question by:2Angel
    LVL 23

    Expert Comment

    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


    'with your script in here :)


    Take a look here for using the FSO :
    LVL 23

    Accepted Solution

       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>

        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 :)
    LVL 23

    Expert Comment

    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  :
    LVL 23

    Expert Comment

    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 ?
    LVL 2

    Author Comment

    Thanks man!
    LVL 23

    Expert Comment

    Your welcome ! Thanks for the points and grade ! I hope this helped you out ! You got it working now ?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now