Jump to content
Sign in to follow this  
xclaim

help to tweak script

Recommended Posts

xclaim

hi i have a script that opens a html file in excel and saves it in xls format. It works great.

problem is that i need to do this for 1700 files and everytime i run it through a batch file my computer keeps opening and closing excel for each file and i cannot use my 6 core computer. Is there a way to make the script run in the background and make Excel open it in the background and also use an existing excel session ?

thanks in advance

here is the script

#Include <Excel.au3>

;local $sfilePath0 =
Local $sFilePath1 = @ScriptDir &"\"&$CmdLine[1]&".html" ;This file should already exist
Local $sFilePath2 = @ScriptDir& $CmdLine[2]& ".xls" ;This file should already exist
Local $oExcel = _ExcelBookOpen($sFilePath1)

; $oExcel.Visible = 0

If @error = 1 Then
    MsgBox(0, "Error!", "Unable to Create the Excel Object")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "Error!", "File does not exist - Shame on you!")
    Exit
EndIf

;MsgBox(0, "Exiting", "Press OK to Save File and Exit")
;_ExcelBookClose($oExcel, 1, 0)

_ExcelBookSaveAs($oExcel, @ScriptDir &"\"& $CmdLine[2] , "xls")

;If Not @error Then MsgBox(0, "Success", "File was Saved!", 3)
_ExcelBookClose($oExcel, 1, 0) ;This method will save then Close the file, without any of the normal prompts, regardless of changes

;$oExcel = _ExcelBookOpen($sFilePath2)

Share this post


Link to post
Share on other sites
DW1

This should get you on your way:

Global Const $xlNormal = -4143

Local $oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 0
Local $fDisplayAlerts = $oExcel.Application.DisplayAlerts
Local $fScreenUpdating = $oExcel.Application.ScreenUpdating
$oExcel.Application.DisplayAlerts = 0
$oExcel.Application.ScreenUpdating = 0

$oExcel.WorkBooks.Open("C:\test1.html", Default, 0)
$oExcel.ActiveWorkbook.Sheets(1).Select()
$oExcel.ActiveWorkBook.SaveAs("C:\test1.xls", $xlNormal, Default, "", Default, Default, 1, 2)
$oExcel.ActiveWorkbook.Close()

$oExcel.WorkBooks.Open("C:\test2.html", Default, 0)
$oExcel.ActiveWorkbook.Sheets(1).Select()
$oExcel.ActiveWorkBook.SaveAs("C:\test2.xls", $xlNormal, Default, "", Default, Default, 1, 2)
$oExcel.ActiveWorkbook.Close()

$oExcel.Application.DisplayAlerts = $fDisplayAlerts
$oExcel.Application.ScreenUpdating = $fScreenUpdating
$oExcel.Application.Quit()
$oExcel = ''

Share this post


Link to post
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
Sign in to follow this  

×