using SaveAs to save 'only' one sheet from one book to a new file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to save just ONLY one sheet from a work book to with many sheet's to a new htm(l) file.

But with the following code, it saves all the sheets and just defaults to the one sheet when the htm file is opened, but all sheets are there and visible and can be selected.

Any help would be appreciated.

Thanks in andvance,
-Randy W


$excel = new COM("Excel.Application") or die('...');
$excel -> Workbooks -> Open($file);

$book = $excel -> Workbooks(1);
$sheet = $book -> Worksheets(1);

$newfilename = getcwd()."\graph.htm";
$sheet -> SaveAs($newfilename,44); // <- trying to save just one sheet as htm file.
$book -> Close(true);

unset($sheet);
unset($book);

$excel -> Workbooks -> Close();
$excel -> Quit();
 
Randy W,

I'm not familiar with your programming language, but I've been able to
reproduce your problem within VBA.

Worksheet.Copy will create a copy of that worksheet in a new workbook. So,
the trick to to save the temporary workbook as html then close it.

Sub testit()
ThisWorkbook.Worksheets(1).Copy
Application.ActiveWorkbook.SaveAs "c:\t\test2.htm", 44
Application.ActiveWorkbook.Close SaveChanges:=False
End Sub

Rob


Randy W said:
Hi,

I'm trying to save just ONLY one sheet from a work book to with many sheet's to a new htm(l) file.

But with the following code, it saves all the sheets and just defaults to
the one sheet when the htm file is opened, but all sheets are there and
visible and can be selected.
 
Hey, thanks for the response

I'm using COM through PHP. I've been attempting what you recommeneded, but something's not right in my code. I get what you're saying though and see how it should work

Thanks again
-Randy
 
Back
Top