Consulting

Results 1 to 4 of 4

Thread: Unable to get the SaveAs property of the Workbook class

  1. #1

    Unable to get the SaveAs property of the Workbook class

    Good morning!
    Does anyone know how to solve this??

    I can access all methods and properties, for example, when I call this:

    $worksheet = $output_workbook->Worksheets("Sheet1");
    $range = "B3";
    echo $worksheet->Range($range)->Value;

    It'll show the right value.
    But when I call the save method

    $output_workbook->SaveAs("C:\test.xls");

    it simply doesn't work and I get this error:
    "Unable to get the SaveAs property of the Workbook class"

    I'm dealing with 3 documents that relate with each other, there's an input excel file, an input word file, and the output excel file (the one which throws the exception)

    I noticed when I open the word file, says "A table in this document has become corrupted". I think this may be the problem... but why can I access all the output workbook members except Save and SaveAs?
    This seems strange :S
    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Show the code.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Vista and later will not save to the C:\ root folder. What version are you using?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Hello everybody,

    I think I have the same error on my project.

    I am using a COM object in php to comunicate with excel.

    Here is my code :
    PHP Code:
        function make_reports($date1,$date2,$lg,$team)
        {

            
    $arrd1 explode('-',$date1);
            
    $arrd2 explode('-',$date2);

            
    $date1 $arrd1[2]."-".$arrd1[1]."-".$arrd1[0];
            
    $date2 $arrd2[2]."-".$arrd2[1]."-".$arrd2[0];

            
            if(
    $date1>$date2)
            {
                
    $temp $date1;
                
    $date1 $date2;
                
    $date2 $temp;
            }

            
    connectumt();
            
            if(
    $lg=='es')
            
    $sql "select * from comps_es";
            else
            
    $sql="select * from comps";
            
            
    $res=mysql_query($sql);
            
    $u=0;
            while(
    $row mysql_fetch_row($res))
            {
                
    $t utf8_encode($row[1]);
                
    $compnamearray[$u] = $t;
                
    $u++;
            }
            
    $exceltemplate = new COM("Excel.application");
            
    $exceltemplate->Workbooks->Open('C:\ReportFiles_global\ResultsTemplate.xls');
                    
                    
    $booktemplate=$exceltemplate->Workbooks(1);
                    
    $sheettemplate=$booktemplate->Worksheets(1);
                                
                    
    $app $exceltemplate->Application;
                    
    $app->DisplayAlerts false;
                    
    $name $sheettemplate->name;
                    echo 
    "<br/>".$name."<br/>";
                    
                    for(
    $u $u count($compnamearray);$u++)
                    {
                        
    $col_ $u +67;
                        
    $colchr($col_);
                        
    $cellT=$sheettemplate->Range($col."3"); 
                        
    $temp =  utf8_decode($compnamearray[$u]);
                        
    $cellT->value=$temp;
                    }
                    
    $col_ ++;
                    
    $colchr($col_);                
                    
    $cellT=$sheettemplate->Range($col."3"); 
                    if(
    $lg=='es')
                    
    $temp =  utf8_decode('perfil');
                    else
                    
    $temp =  utf8_decode('Profile');
                    
    $cellT->value=$temp;
                    

                
            
    $sql "select * from results";
            
    $res mysql_query($sql);
            
    //echo "<script>alert(\"hello\")</script>";
            
    $lgn4;
            while(
    $row mysql_fetch_row($res))
            {
                
    $sql_link "select * from links where token = '".$row[1]."'";
                
    //echo "<script>alert(\"$sql_link\")</script>";
                
    if($res_link mysql_query($sql_link))
                {
                    
    ///echo "<script>alert(\"$sql_link\")</script>";
                    
    $row_umt mysql_fetch_row($res_link);
                    if(
    $row_umt[2] == $team || $team == 0)
                    {    
                        
                        
    ///////echo "<script>alert(\"$row_umt[2]\")</script>";
                        //echo "<script>alert(\"$team\")</script>";
                        
                        
    connectLS();
                        
    $sql "select distinct * from lime_tokens_48683 t1, lime_tokens_75547 t2 where (t1.token ='".$row[1]."' or t2.token ='".$row[1]."') and t1.token = t2.token and (t1.completed!='N' or t2.completed!='N')";
                        
    $resls =mysql_query($sql);
                        if(
    $rowls mysql_fetch_row($resls))
                        {
                            
                            
    $t1 explode(" ",$rowls[10]);
                            
    $t2 explode(" ",$rowls[24]);
                            
                            
    $in_range false;
                            if ((
    $t1[0]>=$date1 && $t1[0]<=$date2))
                            {
                                
    $in_range true;
                            }
                            if(
    $t2[0]>=$date1 && $t2[0]<=$date2)
                            {
                                
    $in_range true;
                            }
                            if(
    $in_range)
                            {
                                
    $cellT=$sheettemplate->Range("B$lgn"); 
                                
    $temp =  utf8_decode($rowls[1]." ".$rowls[2]);
                                
    $cellT->value=$temp;
                                for(
    $u $u count($compnamearray);$u++)
                                {
                                    
    $col_ $u +67;
                                    
    $colchr($col_);
                                    
    $cellT=$sheettemplate->Range($col.$lgn); 
                                    
    $temp =  utf8_decode($row[$u 2]);
                                    if(
    $temp == '-1')
                                    {
                                        
    $temp 'NC';
                                        
    $cellT->Font->bold true;
                                        
    $cellT->Font->ColorIndex=3;
                                    }
                                    
    $cellT->value=$temp;
                                }
                                
    $col_++;
                                
    $colchr($col_);
                                
    $cellT=$sheettemplate->Range($col.$lgn); 
                                
    $temp =  utf8_decode($row[13]);
                                if(
    $temp == '')
                                {
                                    
    $temp 'NC';
                                    
    $cellT->Font->bold true;
                                    
    $cellT->Font->ColorIndex=3;
                                }
                                
    $cellT->value=$temp;
                                
    $cellT->value=$temp;
                                
    $lgn++;
                            }
                        }
                        
    connectumt();
                    }
                }
            }
                    
    $lgn--;
                    
    $cells$sheettemplate->Range("B3:N$lgn");
                    
    $cells->Borders->LineStyle=1;
                    
    $cells->Borders->Weight=2.5;
                    
    $cells->Borders->ColorIndex=1;
                    
                    
    $path "C:\ReportFiles_global\Report Team ".$team." from ".$date1." until ".$date2.".xls";
                    echo 
    $path;
                    
    $booktemplate->saveas($path);
                    
    $app->DisplayAlerts true;
                    
    //Echo " Echo num 5 </br>";            
                    
    unset($sheettemplate);//Lib?tion de $sheet
                    
    unset($booktemplate);//Lib?tion de $book
                    
    unset($app);
                    
    $exceltemplate->Workbooks->Close();
                    
    $exceltemplate->Quit();

                    unset(
    $exceltemplate);

                    
            return 
    $path;
            
            
        }
    ?> 
    When I use this function i get the following message :

    Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Unable to get the SaveAs property of the Workbook class' in C:\Program Files\EasyPHP-5.3.2i\www\functions.php:166 Stack trace: #0 C:\Program Files\EasyPHP-5.3.2i\www\functions.php(166): variant->saveas('C:\ReportFiles_...') #1 C:\Program Files\EasyPHP-5.3.2i\www\Reports.php(13): make_reports('01-01-2010', '30-09-2010', 'en', '0') #2 {main} thrown in C:\Program Files\EasyPHP-5.3.2i\www\functions.php on line 166

    It also seems that my excel licence is over, is it a "real" issue ?

    Thanks in advance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •