Jump to content

Error on opening excel file when the file already opened


Recommended Posts

Hi,

I have a script that supposed to open an excel file using the excel UDF.

The script has an error when trying to open the same excel file that was opened and modifyed.

How do I correct this error???

Steps:

1. Run the script once and open a monitor.txt file

2. Modify the excel file and don't save it.

3. Repeat step 1

Note: Create monitor.txt file ithat containing the following context:

Date Report,Name,Process Id,Parent ProcessId,Owner,Priority,Executable path,CPU%,Memory Size,CommandLine,CreationDate,Description,ExecutionState,Handle,HandleCount,KernelModeTime,MaximumWo

rkingSetSiz,MinimumWorkingSetSize,OSName,OSCreationClassName,OtherOperationCount,OtherTransferCount,

PageFaults,PageFileUsage,PeakPageFileUsage,PeakVirtualSize,PrivatePageCount,QuotaNonPagedPoolUsage,Q

uotaPagedPoolUsage,QuotaPeakNonPagedPoolUsage,QuotaPeakPagedPoolUsage,ReadOperationCount,ReadTransfe

rCount,SessionId,Status,ThreadCount,UserModeTime,VirtualSize,WindowsVersion,WriteOperationCount,Writ

eTransferCount

5/11/2008 8:00:32 AM,IEXPLORE.EXE,3688,1272,EMEA\kadar,8,C:\Program Files\Internet Explorer\IEXPLORE.EXE,0,7319552,"C:\Program Files\Internet Explorer\IEXPLORE.EXE" ,05/06/2008 16:57:11,IEXPLORE.EXE,,3688,493,79687500,1413120,204800,Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1,Win32_OperatingSystem,18078,615249,94872,22757376,31850496,155885568,22757376,17336,

159892,20904,165436,15245,37389353,0,,10,77343750,137764864,5.1.2600,850,1309172

5/11/2008 8:00:33 AM,IEXPLORE.EXE,3288,1272,EMEA\kadar,8,C:\Program Files\Internet Explorer\IEXPLORE.EXE,0,339046400,"C:\Program Files\Internet Explorer\IEXPLORE.EXE" ,05/06/2008 17:24:05,IEXPLORE.EXE,,3288,3423,239218750,1413120,204800,Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1,Win32_OperatingSystem,278349,26346801,1980505,335241216,337649664,771731456,33524121

6,18952,182500,21660,192164,179535,241059433,0,,14,1053281250,763240448,5.1.2600,6829,40318602

5/11/2008 8:00:34 AM,IEXPLORE.EXE,2836,1272,EMEA\kadar,8,C:\Program Files\Internet Explorer\IEXPLORE.EXE,0,12427264,"C:\Program Files\Internet Explorer\IEXPLORE.EXE" ,05/07/2008 09:56:21,IEXPLORE.EXE,,2836,506,71562500,1413120,204800,Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1,Win32_OperatingSystem,80063,1687745,38625,23040000,35545088,306950144,23040000,16176

,457300,19512,477172,13371,164322274,0,,10,39218750,289878016,5.1.2600,1440,1291690

5/11/2008 8:00:35 AM,IEXPLORE.EXE,2728,1272,EMEA\kadar,8,C:\Program Files\Internet Explorer\IEXPLORE.EXE,0,22204416,"C:\Program Files\Internet Explorer\IEXPLORE.EXE" ,05/07/2008 10:30:11,IEXPLORE.EXE,,2728,670,73125000,1413120,204800,Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1,Win32_OperatingSystem,331138,92372155,53536,26468352,36216832,176939008,26468352,203

52,179972,23232,199036,11560,7597932,0,,12,324218750,161882112,5.1.2600,919,1454653

The Script is:

#include-once
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ExcelCOM_UDF.au3>

Excel()

Func Excel()
    Local $oExcel
    $sFilter = "*monitor.txt"
    $sTempFile = FileOpenDialog("Open script", @ScriptDir, "*monitor.txt (*.txt)", 1)
    If $sTempFile <> "" Then
        If Not WinExists("Microsoft Excel - " & _FileStripPath($sTempFile, 4), "") Then
            $flgCreateExcel = 1
            $oExcel = _ExcelBookOpenTxt(@ScriptDir & "\" & _FileStripPath($sTempFile, 12))
            If $oExcel <> 0 Then
                _ExcelFontSetProperties($oExcel, 1, 1, 1, 40, True)
                _ExcelBookSaveAs($oExcel, @ScriptDir & "\" & _FileStripPath($sTempFile, 4) & ".xls", "xls", 0, 1)
            EndIf
            $flgCreateExcel = 0
        Else
            $flgCreateExcel = 1
            $Helpme = WinClose("Microsoft Excel - " & _FileStripPath($sTempFile, 4), "")
            $oExcel = _ExcelBookOpenTxt(@ScriptDir & "\" & _FileStripPath($sTempFile, 12))
            If $oExcel <> 0 Then
                _ExcelFontSetProperties($oExcel, 1, 1, 1, 40, True)
                _ExcelBookSaveAs($oExcel, @ScriptDir & "\" & _FileStripPath($sTempFile, 4) & ".xls", "xls", 0, 1)
            EndIf
            $flgCreateExcel = 0
        EndIf
    EndIf
EndFunc 

Func _FileStripPath($FileName, $Flags = 12)
    Dim $Temp, $Return = ''
    If $Flags < 0 Then $Flags = 12
    $Temp = _FileParsePath($FileName)
    If BitAND($Flags, 1) Then $Return = $Return & $Temp[0]
    If BitAND($Flags, 2) Then $Return = $Return & $Temp[1]
    If BitAND($Flags, 4) Then $Return = $Return & $Temp[2]
    If BitAND($Flags, 8) Then $Return = $Return & $Temp[3]
    Return $Return
EndFunc

Func _FileParsePath($FileName)
    Dim $Return[4]
    Dim $Len
    If StringMid($FileName, 2, 1) = ":" Then
        $Return[0] = StringLeft($FileName, 2)
        $FileName = StringRight($FileName, StringLen($FileName) - 2)
    Else
        $Return[0] = ''
    EndIf
    $Len = StringInStr($FileName, "\", 0, -1)
    $Return[1] = StringLeft($FileName, $Len)
    $FileName = StringRight($FileName, StringLen($FileName) - $Len)
    $Len = StringInStr($FileName, ".", 0, -1)
    $Return[2] = StringLeft($FileName, $Len - 1)
    $FileName = StringRight($FileName, StringLen($FileName) - $Len + 1)
    $Return[3] = $FileName
    Return $Return
EndFunc

The error is:

>Running:(3.2.11.1):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\QA\MyTools\ProcessMonitor\MonMon\Test\Excel.au3"  
C:\QA\MyTools\ProcessMonitor\MonMon\Test\ExcelCOM_UDF.au3 (362) : ==> The requested action with this object has failed.:
If $sPassword = "" And $sWritePassword = "" Then $oExcel.ActiveWorkBook.SaveAs($sFilePath, $sType, Default, Default, Default, Default, $iAccessMode, $iConflictResolution)
If $sPassword = "" And $sWritePassword = "" Then $oExcel.ActiveWorkBook.SaveAs($sFilePath, $sType, Default, Default, Default, Default, $iAccessMode, $iConflictResolution)^ ERROR

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

I just ran the code and got no errors... I am running the non beta ver 3.2.10.0. If you run with that version do you get the same error? Also what OS and version of excel are you running? I'm running XP with office 2000

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

I just ran the code and got no errors... I am running the non beta ver 3.2.10.0. If you run with that version do you get the same error? Also what OS and version of excel are you running? I'm running XP with office 2000

You have not got error since you did not modified the excel file and left it unsaved? isnt it?

If the file saved then there is no error. follow the steps...remember to keep the first excel file opened.

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...