Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't save xls as htm file

Status
Not open for further replies.

nivini

Programmer
Mar 24, 2004
64
0
0
I have this code
Code:
<script>
sub document_onload()
dim xcl, xlbook
dim pathStr, fname
pathstr="c:\[URL unfurl="true"]www\test.xls"[/URL]
set xcl=createobject("excel.application")
set xlbook=getobject(Pathstr)
xlbook.saveas "c:\[URL unfurl="true"]www\test.htm",[/URL] xlHTML
end sub
</script>

the test.htm is not created, how come?
what do i have to do to create a html file?
please help
nivini
 
Script does not recognize named enum, use 44 instead xlHTML.

combo
 
Try to make excel visible and see what is going on:

set xcl=createobject("excel.application")
xcl.Visible=True

I would also use excel instance to open workbook:

set xlbook=xcl.Workbooks.Open(Pathstr)

I am not script expert, maybe named parameters could help (like in vba):

xlbook.saveas FileName:="c:\ FileFormat:=44

combo
 
combo, thanks again, but no go,
I've tried all suggested combination and the test.htm file is not created,
if you have other solution i'll be more then happy to try.
Do you know where can i find more about vbscript?
help is very needed
nivini
 
Hi,
do you have any error message, does the procedure run (try to add a message). For me this works in regular (vbs) script file, fails if I try to save in non-existing directory (xcl.visible=true for testing only):

dim xcl, xlbook
dim pathStr, fname
pathstr="c:\test.xls"
set xcl=createobject("excel.application")
xcl.visible=true
set xlbook=xcl.workbooks.open(Pathstr)
xlbook.saveas "c:\test.htm", 44

You can find and download MS script56.chm help file, for instance from here.

combo
 
To:eek:p
You keep saying not working, what exact script and environment are you testing. That part does not come obvious. You must state that clearly, otherwise you are wasting people's time.

If you are running it in a html page (as it seems to be in your first post), apart from a common occurrence of a warning---which can be bypass by hta approach,

[1] you must not use document_onload, there is no such thing;

[2] you should specify the language.

><script>
[tt]<script [red]language="vbscript"[/red]>[/tt]

>sub document_onload()
[tt]sub [red]window[/red]_onload[/tt]

As to the proper coding of the sub, I won't repeat what combo noted except...

[3] that you might need to set
[tt]xcl.displayalerts=false[/tt]
if you don't want a prompt for overwriting if the html file exists;

[4] that you _must_ close the xlbook object and quit the xcl after saveas.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top