Edit HTML file using Visual Basic 6

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
LVL 2
2AngelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Shane Russell2nd Line Desktop SupportCommented:
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
 
Shane Russell2nd Line Desktop SupportCommented:
   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

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Shane Russell2nd Line Desktop SupportCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Shane Russell2nd Line Desktop SupportCommented:
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
 
2AngelAuthor Commented:
Thanks man!
0
 
Shane Russell2nd Line Desktop SupportCommented:
Your welcome ! Thanks for the points and grade ! I hope this helped you out ! You got it working now ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.