Link to home
Start Free TrialLog in
Avatar of 2Angel
2Angel

asked on

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
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

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
ASKER CERTIFIED SOLUTION
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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 ?
Avatar of 2Angel
2Angel

ASKER

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