-
Posts
42 -
Joined
-
Last visited
Everything posted by Kaimberex
-
I am having some difficulties figuring out why when using the _Excel_BookClose function if I have an Excel sheet already opened that was not opened with _Excel_BookOpen it still closes the workbook. Here is a snippet of some of my code. Any guidance is appreciated! $ConfigFileCheckPrinterSelection = IniRead($ConfigFile, "Printers", "Selected Printer", "Microsoft XPS Document Writer") $oExcelChecklist = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathChecklist = @ScriptDir & "\Documents\New Hire Checklist.xlsx" $workbookChecklist = _Excel_BookOpen($oExcelChecklist, $sFilePathChecklist) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Checklist successfully printed.") $oExcelQuickGuide = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathQuickGuide = @ScriptDir & "\Documents\New Hire Quick Guide.xlsx" $workbookQuickGuide = _Excel_BookOpen($oExcelQuickGuide, $sFilePathQuickGuide) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Print($oExcelQuickGuide, $workbookQuickGuide.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Quick Guide successfully printed.") _Excel_BookClose($workbookChecklist, False) _Excel_BookClose($workbookQuickGuide, False) I do not receive any errors. Just any excel workbooks I had open before this particular function runs gets closed after the documents print.
-
Detecting changes in a multiple GUI program
Kaimberex replied to Kaimberex's topic in AutoIt General Help and Support
Sorry long day, The scenario would be if a user sets the options in the settings page and clicks save the save button is greyed out indicating that the settings have been saved. but if a user decides to change a setting and wants to save again they cant because the button is greyed out until you open the settings window again. I would like to detect changes either with a loop or a OnEvent function. The DetectSettingsChange() function works by itself but I want it to detect every couple of milliseconds if a change has been made on the window and make the Save button active again. -
This issue happens to me from time to time as well. Usually I just close and reopen Studio and it works again.
- 995 replies
-
- isn autoit studio
- isn
-
(and 3 more)
Tagged with:
-
Okay so let me try to explain what I am trying to do and my issue. I am developing an inhouse program for my job and I am stumped on a particular scenario. Hoping someone can help me accomplish what I am trying to do. I am pretty sure it can be done using OnEvent Mode but I am still kind of new at that part of Autoit. I will attach my project here because it has a lot of includes and is using ISN Autoit Studio which saves its code differently. Documents.zip The scenario would be if a user sets the options in the settings page and clicks save the save button is greyed out indicating that the settings have been saved. but if a user decides to change a setting and wants to save again they cant because the button is greyed out until you open the settings window again. I would like to detect changes either with a loop or a OnEvent function. The DetectSettingsChange() function works by itself but I want it to detect every couple of milliseconds if a change has been made on the window and make the Save button active again. Here is my main Script: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Beta #AutoIt3Wrapper_Res_Description=Utility to automatically enter information into New Hire Imaging checklist. #AutoIt3Wrapper_Res_Fileversion=1.1.4.5 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_LegalCopyright=All Rights Reserved.2016 #AutoIt3Wrapper_Res_Language=1033 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;***************************************** ; AutoIt Version: 3.3.14.1 ; Author: Eric Behrens ; IT - Deskside Services ; Allianz Global Corporate & Specialty AG ; ; ; ;~ Script Function: ; ; ;***************************************** #include "Forms\New Hire Imaging Checklist Input Utility.isf" #include "Forms\Settings.isf" #include <Misc.au3> #include <Excel.au3> #include <Array.au3> #include <GuiEdit.au3> #include "Forms\About.isf" #include <File.au3> #include <AD.au3> #include <Date.au3> ;Check if another instance of this application is lready running. If detected, kill new instance and keep original. If _Singleton("New Hire Imaging Checklist Input Utility", 1) = 0 Then MsgBox(16, "Error", "Another instance of this program is already running.") Exit EndIf #Region Global Variables Global $oExcelChecklist, $sFilePathChecklist, $workbookChecklist, $oExcelQuickGuide, $sFilePathQuickGuide, $workbookQuickGuide, $LogFileDirChoose, $SelectedPrinter, $IsLoggingEnabled Global $defPrtNm, $DefaultPrinter, $DocumentsProcessed, $LogDir, $ConfigFile #EndRegion Global Variables #Region Declare Variables $DocumentsProcessed = False #EndRegion Declare Variables #Region Config.ini Settings ;Create the .ini file $ConfigFile = @ScriptDir & "\Config.ini" If FileExists($ConfigFile) = 0 Then _FileCreate($ConfigFile) $ConfigFileIsLoggingEnabled = IniRead($ConfigFile, "Logging", "Logging", "Disabled") $ConfigFileCheckPrinterSelection = IniRead($ConfigFile, "Printers", "Selected Printer", "Microsoft XPS Document Writer") $ConfigFileCheckLogDir = IniRead($ConfigFile, "Logging", "Log Dir", "") $ConfigFileNamingUtility = IniRead($ConfigFile, "Integration", "Workstation Naming Utility", "False") #EndRegion Config.ini Settings #Region Process Config Paramaters. GUICtrlSetData($cboxPrinters, $ConfigFileCheckPrinterSelection) #EndRegion Process Config Paramaters. GetTechnicianName() GUICtrlSetState($MenuItemPrint,$GUI_DISABLE) GUICtrlSetState($MenuItemTransferUtility, $GUI_DISABLE) GUISetState(@SW_SHOW, $MainGUI) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $btnUpdate AddToSpreadsheet() Case $btnExit Exit Case $MenuItemPrint PrintDocuments() Case $MenuItemSettings GUISetState(@SW_DISABLE, $MainGUI) SettingsGUI() GUISetState(@SW_ENABLE, $MainGUI) Case $MenuItemExit Exit Case $MenuItemAbout GUISetState(@SW_DISABLE, $MainGUI) AboutBox() GUISetState(@SW_ENABLE, $MainGUI) EndSwitch WEnd Func AddToSpreadsheet() Local $UserID = GUICtrlRead($inputUserID) Local $ComputerName = GUICtrlRead($inputComputerName) Local $UserName = GUICtrlRead($inputName) Local $LotusPW = GUICtrlRead($inputLotusPW) Local $PhoneNo = GUICtrlRead($inputPhoneNo) Local $PW = GUICtrlRead($inputPW) Local $StartDate = GUICtrlRead($inputDate) Local $DeskLocation = GUICtrlRead($inputLocation) Local $SerialNumber = GUICtrlRead($inputSerialNo) Local $Technician = GUICtrlRead($inputTechnician) If GUICtrlRead($inputUserID) = "" Then MsgBox(16, "Missing info", "Please enter a User ID to continue", 0) ElseIf GUICtrlRead($inputComputerName) = "" Then MsgBox(16, "Missing info", "Please enter a Computer Name to continue", 0) ElseIf GUICtrlRead($inputName) = "" Then MsgBox(16, "Missing info", "Please enter a Name to continue", 0) ElseIf GUICtrlRead($inputLotusPW) = "" Then MsgBox(16, "Missing info", "Please enter a Lotus Notes Password to continue", 0) ElseIf GUICtrlRead($inputPhoneNo) = "" Then MsgBox(16, "Missing info", "Please enter a Phone Number to continue", 0) ElseIf GUICtrlRead($inputPW) = "" Then MsgBox(16, "Missing info", "Please enter a Windows Password to continue", 0) ElseIf GUICtrlRead($inputLocation) = "" Then MsgBox(16, "Missing info", "Please enter a Location to continue", 0) ElseIf GUICtrlRead($inputSerialNo) = "" Then MsgBox(16, "Missing info", "Please enter a Serial Number to continue", 0) Else GUICtrlSetState($btnUpdate,$GUI_DISABLE) GUICtrlSetState($btnExit,$GUI_DISABLE) $oExcelChecklist = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathChecklist = @ScriptDir & "\Documents\New Hire Checklist.xlsx" $workbookChecklist = _Excel_BookOpen($oExcelChecklist, $sFilePathChecklist) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $UserName, "D42") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $ComputerName, "E43") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $UserID, "J42") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $LotusPW, "K44") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $PhoneNo, "M42") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $PW, "C44") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $StartDate, "C45") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $DeskLocation, "J45") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $SerialNumber, "K43") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $Technician, "N43") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Sleep(500) $oExcelQuickGuide = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathQuickGuide = @ScriptDir & "\Documents\New Hire Quick Guide.xlsx" $workbookQuickGuide = _Excel_BookOpen($oExcelQuickGuide, $sFilePathQuickGuide) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $UserName, "C8") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $UserID, "H15") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $PW, "H17") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $LotusPW, "H19") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $PhoneNo, "H21") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $DocumentsProcessed = True EndIf PrintDocuments() _Excel_BookClose($workbookChecklist, False) _Excel_BookClose($workbookQuickGuide, False) LoggingToExcel() ClearForm() GUICtrlSetState($btnUpdate,$GUI_ENABLE) GUICtrlSetState($btnExit,$GUI_ENABLE) EndFunc ;==>AddToSpreadsheet Func DefaultPrinterChange() $sPrinterName = '"\\VUSSLBSRFS1001.agcs.biz\SecureColor"' $DefaultPrinter = _GetDefaultPrinter() RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterName, "", @SW_HIDE) EndFunc ;==>DefaultPrinterChange Func DisableLoggingEnableButton() $IsLoggingEnabled = 1 GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_DISABLE) GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_ENABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_ENABLE) EndFunc ;==>DisableLoggingEnableButton Func DisableLoggingDisableButton() $IsLoggingEnabled = 0 GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_DISABLE) GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_ENABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_DISABLE) EndFunc ;==>DisableLoggingDisableButton Func SettingsGUI() ;~ Opt("GUIOnEventMode", 1) ; Change to OnEvent mode GUICtrlSetState($btnSettingsSave, $GUI_ENABLE) Switch $ConfigFileIsLoggingEnabled Case "Enabled" GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_DISABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_ENABLE) Case "Disabled" GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_DISABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_DISABLE) EndSwitch EnumeratePrinterList() GUICtrlSetData($cboxPrinters, $ConfigFileCheckPrinterSelection) GUICtrlSetData($inputSettingsLogDir, $ConfigFileCheckLogDir) _GUICtrlEdit_SetSel($inputSettingsLogDir, 1, 1) GUISetState(@SW_SHOW, $Settings) While 1 DetectSettingsChanges() $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Settings) GUISetState(@SW_SHOW, $MainGUI) ExitLoop Case $btnSettingsOK ;~ DetectSettingsChanges() GUISetState(@SW_HIDE, $Settings) GUISetState(@SW_SHOW, $MainGUI) ExitLoop Case $btnSettingsSave GUICtrlSetState($btnSettingsOK,$GUI_DISABLE) Sleep(250) WriteSettingsToFile() GUICtrlSetState($btnSettingsSave, $GUI_DISABLE) Sleep(250) GUICtrlSetState($btnSettingsOK, $GUI_ENABLE) Case $btnSettingsLoggingEnabled DisableLoggingEnableButton() Case $btnSettingsLoggingDisabled DisableLoggingDisableButton() Case $btnSettingsChooseLogDir SelectLogDir() Case $btnSettingsOpenLog ;~ DetectSettingsChanges() EndSwitch WEnd EndFunc ;==>SettingsGUI Func EnumeratePrinterList() $wbemFlagReturnImmediately = "&h10" $wbemFlagForwardOnly = "&h20" $WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $aItems = $WMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) For $printer In $aItems GUICtrlSetData($cboxPrinters, $printer.Name) Next EndFunc ;==>EnumeratePrinterList Func SelectLogDir() $LogFileDirChoose = FileSaveDialog("Choose a location to save the log file", @ScriptDir, "Excel Files(*.xls)", $FD_PATHMUSTEXIST, "New Hire Log.xls", $Settings) GUICtrlSetData($inputSettingsLogDir, $LogFileDirChoose) _GUICtrlEdit_SetSel($inputSettingsLogDir, 1, 1) ;~ MsgBox(0,"", $LogFileDirChoose) EndFunc ;==>SelectLogDir Func WriteSettingsToFile() $sFilePathLogFile = $ConfigFileCheckLogDir $Logging = "" $SelectedPrinter = GUICtrlRead($cboxPrinters) $LogDir = GUICtrlRead($inputSettingsLogDir) ;If log file does bot exist then create a new blank log file. If $ConfigFileIsLoggingEnabled = "Enabled" Or $IsLoggingEnabled = 1 Then If Not FileExists($LogDir) Then $oExcelLogFile = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathLogFile = $ConfigFileCheckLogDir $CreateNewLogDirBook = _Excel_BookNew($oExcelLogFile) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error creating workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Date", "A1") _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Build Technician", "B1") _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "User ID", "C1") _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "User Name", "D1") _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Computer Name", "E1") _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Serial Number", "F1") _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Start Date", "G1") $oExcelLogFile.ActiveSheet.Columns(1).AutoFit $oExcelLogFile.ActiveSheet.Columns(2).AutoFit $oExcelLogFile.ActiveSheet.Columns(3).AutoFit $oExcelLogFile.ActiveSheet.Columns(4).AutoFit $oExcelLogFile.ActiveSheet.Columns(5).AutoFit $oExcelLogFile.ActiveSheet.Columns(6).AutoFit $oExcelLogFile.ActiveSheet.Columns(7).AutoFit If $ConfigFileCheckLogDir = "" Then $sFilePathLogFile = $LogFileDirChoose _Excel_BookSaveAs($CreateNewLogDirBook, $sFilePathLogFile, $xlExcel8, True) If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcelLogFile) Exit EndIf _Excel_Close($oExcelLogFile) EndIf EndIf If $IsLoggingEnabled = 0 Then $Logging = "Disabled" If $IsLoggingEnabled = 1 Then $Logging = "Enabled" If GUICtrlRead($cbSettingsIntegrateNamingUtility) = 1 Then $Integration = "True" If GUICtrlRead($cbSettingsIntegrateNamingUtility) = 4 Then $Integration = "False" IniWrite($ConfigFile, "Integration", "Workstation Naming Utility", $Integration) IniWrite($ConfigFile, "Logging", "Logging", $Logging) IniWrite($ConfigFile, "Printers", "Selected Printer", $SelectedPrinter) IniWrite($ConfigFile, "Logging", "Log Dir", $LogDir) EndFunc ;==>WriteSettingsToFile Func _GetDefaultPrinter() ; CyberSlug - 18 Nov 2004 Local $key, $default If @OSType = "WIN32_WINDOWS" Then $key = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers" $defPrtNm = RegRead("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers", "Default") Else ;WIN_NT type $key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" $default = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device") $defPrtNm = StringLeft($default, StringInStr($default, ",") - 1) Return $defPrtNm EndIf EndFunc ;==>_GetDefaultPrinter Func _PrintMgr_SetDefaultPrinter($sPrinterName) Local $iRet = 1 Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") If Not IsObj($oWMIService) Then Return SetError(1, 0, 0) Local $oPrinters = $oWMIService.ExecQuery("Select * from Win32_Printer where DeviceID = '" & $sPrinterName & "'") If Not IsObj($oPrinters) Then Return SetError(1, 0, 0) For $oPrinter In $oPrinters $iRet = $oPrinter.SetDefaultPrinter() Next Return ($iRet = 0 ? 1 : SetError($iRet, 0, 0)) EndFunc ;==>_PrintMgr_SetDefaultPrinter Func PrintDocuments() If $DocumentsProcessed = False Then MsgBox(16, "Print Error", "No Data has been entered into Excel documents. Please update form and click Process before printing. ", 0, $MainGUI) Else $ConfigFileCheckPrinterSelection = IniRead($ConfigFile, "Printers", "Selected Printer", "") ;Check printer selected in settings menu. $DefaultPrinter = _GetDefaultPrinter() ;Retrieve Default Printer.Returns FQDN $SearchForSecureColor = StringMid($ConfigFileCheckPrinterSelection, 27) ;Check if SecureColor exists in selected Printer $SearchForSecureBnW = StringMid($ConfigFileCheckPrinterSelection, 27) ;Check if SecureB&W exists in Selected Printer. Local $sPrinterName = "" Local $sSubKey = "" For $i = 1 To 10 $sSubKey = RegEnumKey("HKCU\Printers\Connections", $i) ;Find Keys for Printer Connections If @error Then ExitLoop $PrinterServer = StringMid($sSubKey, 3, 14) ;Trim values to only aquire server name. If StringInStr($sSubKey, "SecureColor") > 0 Then $sPrinterNameColor = "\\" & $PrinterServer & ".agcs.biz\SecureColor" If StringInStr($sSubKey, "SecureB&W") > 0 Then $sPrinterNameBnW = "\\" & $PrinterServer & ".agcs.biz\SecureB&W" ;Convert to string for default printer change command. Next ;~ $msgboxPrint = MsgBox(36, "Print", "Would you like to print the Quick Guide and Checklist?", 0) ;~ Switch $msgboxPrint ;~ Case 6 ;YES If $SearchForSecureColor = "SecureColor" Then ;If Secure Color is selected then $sPrinterNameColor = """\\" & $PrinterServer & ".agcs.biz\SecureColor""" RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterNameColor, "", @SW_HIDE) ;Set SecureColor as Default printer. ;Print Stuff from Excel _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Checklist successfully printed.") _Excel_Print($oExcelQuickGuide, $workbookQuickGuide.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Quick Guide successfully printed.") ;Print Stuff from excel If $DefaultPrinter = "\\" & $PrinterServer & ".agcs.biz\SecureB&W" Then ;If the default OS printer was SecureB&W then $sPrinterName = '"\\' & $PrinterServer & '.agcs.biz\SecureB&W"' RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterName, "", @SW_HIDE) ;this command must be passed for a network printer because PrintMGRUDF does not support network printers at this time. Else ;If a local printer was the default then use built it PrintMGR function _PrintMgr_SetDefaultPrinter($DefaultPrinter) _PrintMgr_SetDefaultPrinter($DefaultPrinter) EndIf Else _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Checklist successfully printed.") _Excel_Print($oExcelQuickGuide, $workbookQuickGuide.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Quick Guide successfully printed.") EndIf ;~ Case 7 ;NO ;~ EndSwitch EndIf EndFunc ;==>PrintDocuments Func AboutBox() $FileVersion = FileGetVersion(@ScriptFullPath) GUICtrlSetData($lblAboutVersion, $FileVersion) GUISetState(@SW_SHOW, $About) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $About) GUISetState(@SW_SHOW, $MainGUI) ExitLoop Case $btnAboutClose GUISetState(@SW_HIDE, $About) GUISetState(@SW_SHOW, $MainGUI) ExitLoop EndSwitch WEnd EndFunc ;==>AboutBox Func GetTechnicianName() _AD_Open() $TechName = @UserName $TechFQDN = _AD_SamAccountNameToFQDN($TechName) $TechDisplayName = _AD_FQDNToDisplayname($TechFQDN) GUICtrlSetData($inputTechnician, $TechDisplayName) EndFunc ;==>GetTechnicianName Func LoggingToExcel() Local $UserID = GUICtrlRead($inputUserID) Local $ComputerName = GUICtrlRead($inputComputerName) Local $UserName = GUICtrlRead($inputName) Local $StartDate = GUICtrlRead($inputDate) Local $SerialNumber = GUICtrlRead($inputSerialNo) Local $TechName = GUICtrlRead($inputTechnician) Local $TodaysDate = _Date_Time_GetLocalTime() If $ConfigFileIsLoggingEnabled = "Enabled" Or $IsLoggingEnabled = 1 Then $oExcelLogFile = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathLogFile = $ConfigFileCheckLogDir If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error creating workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $workbookLogFile = _Excel_BookOpen($oExcelLogFile, $sFilePathLogFile) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRange = $workbookLogFile.ActiveSheet.UsedRange.SpecialCells($xlCellTypeLastCell) _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, _Date_Time_SystemTimeToDateTimeStr($TodaysDate), "A" & $oRange.row + 1) _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $TechName, "B" & $oRange.row + 1) _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $UserID, "C" & $oRange.row + 1) _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $UserName, "D" & $oRange.row + 1) _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $ComputerName, "E" & $oRange.row + 1) _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $SerialNumber, "F" & $oRange.row + 1) _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $StartDate, "G" & $oRange.row + 1) ;Auto Fit column width $oExcelLogFile.ActiveSheet.Columns(1).AutoFit $oExcelLogFile.ActiveSheet.Columns(2).AutoFit $oExcelLogFile.ActiveSheet.Columns(3).AutoFit $oExcelLogFile.ActiveSheet.Columns(4).AutoFit $oExcelLogFile.ActiveSheet.Columns(5).AutoFit $oExcelLogFile.ActiveSheet.Columns(6).AutoFit $oExcelLogFile.ActiveSheet.Columns(7).AutoFit _Excel_Close($oExcelLogFile, True) EndIf EndFunc ;==>LoggingToExcel Func ClearForm() GUiCtrlSetData($inputUserID,"") GUiCtrlSetData($inputComputerName,"") GUiCtrlSetData($inputName,"") GUiCtrlSetData($inputLotusPW,"") GUiCtrlSetData($inputPhoneNo,"") GUiCtrlSetData($inputPW,"") GUiCtrlSetData($inputDate,"") GUiCtrlSetData($inputLocation,"") GUiCtrlSetData($inputSerialNo,"") $DocumentsProcessed = False EndFunc Func DetectSettingsChanges() ;~ Sleep(1000) $DetectPrinterChange = GUICtrlRead($cboxPrinters) $DetectLogDirChange = GUICtrlRead($inputSettingsLogDir) $DetectLogEnabledChange = GUICtrlGetState($btnSettingsLoggingEnabled) If $DetectPrinterChange not = $ConfigFileCheckPrinterSelection Then Sleep(100) Else GUICtrlSetState($btnSettingsSave, $GUI_ENABLE) EndIf If $DetectLogDirChange Not = $ConfigFileCheckLogDir Then Sleep(100) Else GUICtrlSetState($btnSettingsSave, $GUI_ENABLE) EndIf ;~ If $DetectLogEnabledChange = 144 Then ;~ MsgBox(0,"","You cannot press Enabled") ;~ ElseIf $DetectLogEnabledChange = 80 Then ;~ MsgBox(0,"","You can press Enabled") ;~ EndIf ;~ ConsoleWrite($test1 & @CRLF) ;~ $test2 = GUICtrlGetState($btnSettingsLoggingDisabled) ;~ ConsoleWrite($test2 & @CRLF) EndFunc Here are the forms in au3 format in case you dont have ISN AutoIt Studio. New Hire Imaging Checklist Input Utility.au3 Settings.au3
-
When you compile a script any includes you have in your script will be added to the top when its compiled try running a syntax check in SciTE before compiling and you can get the exact line number.
-
I have a compiled script that runs fine until the FileSaveDialog function is ran, Once that has been called my script immediately triggers the AV and my .exe gets deleted from the computer. I submitted the source code for my script to symantec and they whitelisted my file however since the original file was deleted I had to recompile the file and now it has a new hash so the whitelisting is practically irrelevant. Can anyone think of a reason why the FileSaveDialog would trigger an AV? The Large blocks of commented out code is my attempt to isolate what is causing the AV to trigger. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Beta #AutoIt3Wrapper_Res_Description=Utility to automatically enter information into New Hire Imaging checklist. #AutoIt3Wrapper_Res_Fileversion=1.1.4.6 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_LegalCopyright=All Rights Reserved.2016 #AutoIt3Wrapper_Res_Language=1033 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "Forms\New Hire Imaging Checklist Input Utility.isf" #include "Forms\Settings.isf" #include <Misc.au3> #include <Excel.au3> ;~ #include <Array.au3> #include <GuiEdit.au3> #include "Forms\About.isf" #include <File.au3> #include <AD.au3> #include <Date.au3> ;Check if another instance of this application is lready running. If detected, kill new instance and keep original. If _Singleton("New Hire Imaging Checklist Input Utility", 1) = 0 Then MsgBox(16, "Error", "Another instance of this program is already running.") Exit EndIf #Region Global Variables Global $oExcelChecklist, $sFilePathChecklist, $workbookChecklist, $oExcelQuickGuide, $sFilePathQuickGuide, $workbookQuickGuide, $LogFileDirChoose, $SelectedPrinter, $IsLoggingEnabled Global $defPrtNm, $DefaultPrinter, $DocumentsProcessed, $LogDir #EndRegion Global Variables #Region Declare Variables $DocumentsProcessed = False #EndRegion Declare Variables #Region Config.ini Settings ;Create the .ini file $ConfigFile = @ScriptDir & "\Config.ini" If FileExists($ConfigFile) = 0 Then _FileCreate($ConfigFile) $ConfigFileIsLoggingEnabled = IniRead($ConfigFile, "Logging", "Logging", "Disabled") $ConfigFileCheckPrinterSelection = IniRead($ConfigFile, "Printers", "Selected Printer", "Microsoft XPS Document Writer") $ConfigFileCheckLogDir = IniRead($ConfigFile, "Logging", "Log Dir", "") $ConfigFileNamingUtility = IniRead($ConfigFile, "Integration", "Workstation Naming Utility", "False") #EndRegion Config.ini Settings #Region Process Config Paramaters. GUICtrlSetData($cboxPrinters, $ConfigFileCheckPrinterSelection) #EndRegion Process Config Paramaters. GetTechnicianName() GUICtrlSetState($MenuItemPrint,$GUI_DISABLE) GUICtrlSetState($MenuItemTransferUtility, $GUI_DISABLE) GUISetState(@SW_SHOW, $MainGUI) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $btnUpdate AddToSpreadsheet() Case $btnExit Exit Case $MenuItemPrint PrintDocuments() Case $MenuItemSettings GUISetState(@SW_DISABLE, $MainGUI) SettingsGUI() GUISetState(@SW_ENABLE, $MainGUI) Case $MenuItemExit Exit Case $MenuItemAbout GUISetState(@SW_DISABLE, $MainGUI) AboutBox() GUISetState(@SW_ENABLE, $MainGUI) EndSwitch WEnd Func AddToSpreadsheet() Local $UserID = GUICtrlRead($inputUserID) Local $ComputerName = GUICtrlRead($inputComputerName) Local $UserName = GUICtrlRead($inputName) Local $LotusPW = GUICtrlRead($inputLotusPW) Local $PhoneNo = GUICtrlRead($inputPhoneNo) Local $PW = GUICtrlRead($inputPW) Local $StartDate = GUICtrlRead($inputDate) Local $DeskLocation = GUICtrlRead($inputLocation) Local $SerialNumber = GUICtrlRead($inputSerialNo) Local $Technician = GUICtrlRead($inputTechnician) If GUICtrlRead($inputUserID) = "" Then MsgBox(16, "Missing info", "Please enter a User ID to continue", 0) ElseIf GUICtrlRead($inputComputerName) = "" Then MsgBox(16, "Missing info", "Please enter a Computer Name to continue", 0) ElseIf GUICtrlRead($inputName) = "" Then MsgBox(16, "Missing info", "Please enter a Name to continue", 0) ElseIf GUICtrlRead($inputLotusPW) = "" Then MsgBox(16, "Missing info", "Please enter a Lotus Notes Password to continue", 0) ElseIf GUICtrlRead($inputPhoneNo) = "" Then MsgBox(16, "Missing info", "Please enter a Phone Number to continue", 0) ElseIf GUICtrlRead($inputPW) = "" Then MsgBox(16, "Missing info", "Please enter a Windows Password to continue", 0) ElseIf GUICtrlRead($inputLocation) = "" Then MsgBox(16, "Missing info", "Please enter a Location to continue", 0) ElseIf GUICtrlRead($inputSerialNo) = "" Then MsgBox(16, "Missing info", "Please enter a Serial Number to continue", 0) Else GUICtrlSetState($btnUpdate,$GUI_DISABLE) GUICtrlSetState($btnExit,$GUI_DISABLE) $oExcelChecklist = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathChecklist = @ScriptDir & "\Documents\New Hire Checklist.xlsx" $workbookChecklist = _Excel_BookOpen($oExcelChecklist, $sFilePathChecklist) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $UserName, "D42") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $ComputerName, "E43") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $UserID, "J42") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $LotusPW, "K44") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $PhoneNo, "M42") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $PW, "C44") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $StartDate, "C45") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $DeskLocation, "J45") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $SerialNumber, "K43") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $Technician, "N43") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Sleep(500) $oExcelQuickGuide = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathQuickGuide = @ScriptDir & "\Documents\New Hire Quick Guide.xlsx" $workbookQuickGuide = _Excel_BookOpen($oExcelQuickGuide, $sFilePathQuickGuide) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $UserName, "C8") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $UserID, "H15") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $PW, "H17") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $LotusPW, "H19") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $PhoneNo, "H21") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $DocumentsProcessed = True EndIf PrintDocuments() _Excel_BookClose($workbookChecklist, False) _Excel_BookClose($workbookQuickGuide, False) ;~ LoggingToExcel() ClearForm() GUICtrlSetState($btnUpdate,$GUI_ENABLE) GUICtrlSetState($btnExit,$GUI_ENABLE) EndFunc ;==>AddToSpreadsheet Func DefaultPrinterChange() $sPrinterName = '"\\VUSSLBSRFS1001.agcs.biz\SecureColor"' $DefaultPrinter = _GetDefaultPrinter() RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterName, "", @SW_HIDE) EndFunc ;==>DefaultPrinterChange Func DisableLoggingEnableButton() $IsLoggingEnabled = 1 GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_DISABLE) GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_ENABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_ENABLE) EndFunc ;==>DisableLoggingEnableButton Func DisableLoggingDisableButton() $IsLoggingEnabled = 0 GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_DISABLE) GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_ENABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_DISABLE) EndFunc ;==>DisableLoggingDisableButton Func SettingsGUI() GUICtrlSetState($btnSettingsSave, $GUI_ENABLE) Switch $ConfigFileIsLoggingEnabled Case "Enabled" GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_DISABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_ENABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_ENABLE) Case "Disabled" GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_DISABLE) GUICtrlSetState($inputSettingsLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsChooseLogDir, $GUI_DISABLE) GUICtrlSetState($btnSettingsOpenLog, $GUI_DISABLE) EndSwitch EnumeratePrinterList() GUICtrlSetData($cboxPrinters, $ConfigFileCheckPrinterSelection) GUICtrlSetData($inputSettingsLogDir, $ConfigFileCheckLogDir) _GUICtrlEdit_SetSel($inputSettingsLogDir, 1, 1) GUISetState(@SW_SHOW, $Settings) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Settings) GUISetState(@SW_SHOW, $MainGUI) ExitLoop Case $btnSettingsOK GUISetState(@SW_HIDE, $Settings) GUISetState(@SW_SHOW, $MainGUI) ExitLoop Case $btnSettingsSave GUICtrlSetState($btnSettingsOK,$GUI_DISABLE) Sleep(250) WriteSettingsToFile() GUICtrlSetState($btnSettingsSave, $GUI_DISABLE) Sleep(250) GUICtrlSetState($btnSettingsOK, $GUI_ENABLE) Case $btnSettingsLoggingEnabled DisableLoggingEnableButton() Case $btnSettingsLoggingDisabled DisableLoggingDisableButton() Case $btnSettingsChooseLogDir SelectLogDir() EndSwitch WEnd EndFunc ;==>SettingsGUI Func EnumeratePrinterList() $wbemFlagReturnImmediately = "&h10" $wbemFlagForwardOnly = "&h20" $WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $aItems = $WMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) For $printer In $aItems GUICtrlSetData($cboxPrinters, $printer.Name) Next EndFunc ;==>EnumeratePrinterList Func SelectLogDir() $LogFileDirChoose = FileSaveDialog("Choose a location to save the log file", @ScriptDir, "Excel Files(*.xls)", $FD_PATHMUSTEXIST, "New Hire Log.xls", $Settings) GUICtrlSetData($inputSettingsLogDir, $LogFileDirChoose) _GUICtrlEdit_SetSel($inputSettingsLogDir, 1, 1) ;~ MsgBox(0,"", $LogFileDirChoose) EndFunc ;==>SelectLogDir Func WriteSettingsToFile() $sFilePathLogFile = $ConfigFileCheckLogDir $Logging = "" $SelectedPrinter = GUICtrlRead($cboxPrinters) $LogDir = GUICtrlRead($inputSettingsLogDir) ;If log file does bot exist then create a new blank log file. ;~ If $ConfigFileIsLoggingEnabled = "Enabled" Or $IsLoggingEnabled = 1 Then ;~ If Not FileExists($LogDir) Then ;~ $oExcelLogFile = _Excel_Open(False) ;~ If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;~ $sFilePathLogFile = $ConfigFileCheckLogDir ;~ $CreateNewLogDirBook = _Excel_BookNew($oExcelLogFile) ;~ If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error creating workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;~ _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Date", "A1") ;~ _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Build Technician", "B1") ;~ _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "User ID", "C1") ;~ _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "User Name", "D1") ;~ _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Computer Name", "E1") ;~ _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Serial Number", "F1") ;~ _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Start Date", "G1") ;~ $oExcelLogFile.ActiveSheet.Columns(1).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(2).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(3).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(4).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(5).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(6).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(7).AutoFit ;~ If $ConfigFileCheckLogDir = "" Then $sFilePathLogFile = $LogFileDirChoose ;~ _Excel_BookSaveAs($CreateNewLogDirBook, $sFilePathLogFile, $xlExcel8, True) ;~ If @error Then ;~ MsgBox($MB_SYSTEMMODAL, "Error", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;~ _Excel_Close($oExcelLogFile) ;~ Exit ;~ EndIf ;~ _Excel_Close($oExcelLogFile) ;~ EndIf ;~ EndIf If $IsLoggingEnabled = 0 Then $Logging = "Disabled" If $IsLoggingEnabled = 1 Then $Logging = "Enabled" If GUICtrlRead($cbSettingsIntegrateNamingUtility) = 1 Then $Integration = "True" If GUICtrlRead($cbSettingsIntegrateNamingUtility) = 4 Then $Integration = "False" IniWrite($ConfigFile, "Integration", "Workstation Naming Utility", $Integration) IniWrite($ConfigFile, "Logging", "Logging", $Logging) IniWrite($ConfigFile, "Printers", "Selected Printer", $SelectedPrinter) IniWrite($ConfigFile, "Logging", "Log Dir", $LogDir) EndFunc ;==>WriteSettingsToFile Func _GetDefaultPrinter() ; CyberSlug - 18 Nov 2004 Local $key, $default If @OSType = "WIN32_WINDOWS" Then $key = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers" $defPrtNm = RegRead("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers", "Default") Else ;WIN_NT type $key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" $default = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device") $defPrtNm = StringLeft($default, StringInStr($default, ",") - 1) Return $defPrtNm EndIf EndFunc ;==>_GetDefaultPrinter Func _PrintMgr_SetDefaultPrinter($sPrinterName) Local $iRet = 1 Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") If Not IsObj($oWMIService) Then Return SetError(1, 0, 0) Local $oPrinters = $oWMIService.ExecQuery("Select * from Win32_Printer where DeviceID = '" & $sPrinterName & "'") If Not IsObj($oPrinters) Then Return SetError(1, 0, 0) For $oPrinter In $oPrinters $iRet = $oPrinter.SetDefaultPrinter() Next Return ($iRet = 0 ? 1 : SetError($iRet, 0, 0)) EndFunc ;==>_PrintMgr_SetDefaultPrinter Func PrintDocuments() If $DocumentsProcessed = False Then MsgBox(16, "Print Error", "No Data has been entered into Excel documents. Please update form and click Process before printing. ", 0, $MainGUI) Else $ConfigFileCheckPrinterSelection = IniRead($ConfigFile, "Printers", "Selected Printer", "") ;Check printer selected in settings menu. $DefaultPrinter = _GetDefaultPrinter() ;Retrieve Default Printer.Returns FQDN $SearchForSecureColor = StringMid($ConfigFileCheckPrinterSelection, 27) ;Check if SecureColor exists in selected Printer $SearchForSecureBnW = StringMid($ConfigFileCheckPrinterSelection, 27) ;Check if SecureB&W exists in Selected Printer. Local $sPrinterName = "" Local $sSubKey = "" For $i = 1 To 10 $sSubKey = RegEnumKey("HKCU\Printers\Connections", $i) ;Find Keys for Printer Connections If @error Then ExitLoop $PrinterServer = StringMid($sSubKey, 3, 14) ;Trim values to only aquire server name. If StringInStr($sSubKey, "SecureColor") > 0 Then $sPrinterNameColor = "\\" & $PrinterServer & ".agcs.biz\SecureColor" If StringInStr($sSubKey, "SecureB&W") > 0 Then $sPrinterNameBnW = "\\" & $PrinterServer & ".agcs.biz\SecureB&W" ;Convert to string for default printer change command. Next ;~ $msgboxPrint = MsgBox(36, "Print", "Would you like to print the Quick Guide and Checklist?", 0) ;~ Switch $msgboxPrint ;~ Case 6 ;YES If $SearchForSecureColor = "SecureColor" Then ;If Secure Color is selected then $sPrinterNameColor = """\\" & $PrinterServer & ".agcs.biz\SecureColor""" RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterNameColor, "", @SW_HIDE) ;Set SecureColor as Default printer. ;Print Stuff from Excel _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Checklist successfully printed.") _Excel_Print($oExcelQuickGuide, $workbookQuickGuide.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Quick Guide successfully printed.") ;Print Stuff from excel If $DefaultPrinter = "\\" & $PrinterServer & ".agcs.biz\SecureB&W" Then ;If the default OS printer was SecureB&W then $sPrinterName = '"\\' & $PrinterServer & '.agcs.biz\SecureB&W"' RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterName, "", @SW_HIDE) ;this command must be passed for a network printer because PrintMGRUDF does not support network printers at this time. Else ;If a local printer was the default then use built it PrintMGR function _PrintMgr_SetDefaultPrinter($DefaultPrinter) _PrintMgr_SetDefaultPrinter($DefaultPrinter) EndIf Else _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Checklist successfully printed.") _Excel_Print($oExcelQuickGuide, $workbookQuickGuide.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Quick Guide successfully printed.") EndIf ;~ Case 7 ;NO ;~ EndSwitch EndIf EndFunc ;==>PrintDocuments Func AboutBox() $FileVersion = FileGetVersion(@ScriptFullPath) GUICtrlSetData($lblAboutVersion, $FileVersion) GUISetState(@SW_SHOW, $About) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $About) GUISetState(@SW_SHOW, $MainGUI) ExitLoop Case $btnAboutClose GUISetState(@SW_HIDE, $About) GUISetState(@SW_SHOW, $MainGUI) ExitLoop EndSwitch WEnd EndFunc ;==>AboutBox Func GetTechnicianName() _AD_Open() $TechName = @UserName $TechFQDN = _AD_SamAccountNameToFQDN($TechName) $TechDisplayName = _AD_FQDNToDisplayname($TechFQDN) GUICtrlSetData($inputTechnician, $TechDisplayName) _AD_Close() EndFunc ;==>GetTechnicianName ;~ Func LoggingToExcel() ;~ Local $UserID = GUICtrlRead($inputUserID) ;~ Local $ComputerName = GUICtrlRead($inputComputerName) ;~ Local $UserName = GUICtrlRead($inputName) ;~ Local $StartDate = GUICtrlRead($inputDate) ;~ Local $SerialNumber = GUICtrlRead($inputSerialNo) ;~ Local $TechName = GUICtrlRead($inputTechnician) ;~ Local $TodaysDate = _Date_Time_GetLocalTime() ;~ If $ConfigFileIsLoggingEnabled = "Enabled" Or $IsLoggingEnabled = 1 Then ;~ $oExcelLogFile = _Excel_Open(False) ;~ If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;~ $sFilePathLogFile = $ConfigFileCheckLogDir ;~ If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error creating workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;~ $workbookLogFile = _Excel_BookOpen($oExcelLogFile, $sFilePathLogFile) ;~ If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;~ $oRange = $workbookLogFile.ActiveSheet.UsedRange.SpecialCells($xlCellTypeLastCell) ;~ _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, _Date_Time_SystemTimeToDateTimeStr($TodaysDate), "A" & $oRange.row + 1) ;~ _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $TechName, "B" & $oRange.row + 1) ;~ _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $UserID, "C" & $oRange.row + 1) ;~ _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $UserName, "D" & $oRange.row + 1) ;~ _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $ComputerName, "E" & $oRange.row + 1) ;~ _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $SerialNumber, "F" & $oRange.row + 1) ;~ _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $StartDate, "G" & $oRange.row + 1) ;~ ;~ ;Auto Fit column width ;~ $oExcelLogFile.ActiveSheet.Columns(1).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(2).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(3).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(4).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(5).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(6).AutoFit ;~ $oExcelLogFile.ActiveSheet.Columns(7).AutoFit ;~ _Excel_Close($oExcelLogFile, True) ;~ EndIf ;~ ;~ ;~ ;~ EndFunc ;==>LoggingToExcel Func ClearForm() GUiCtrlSetData($inputUserID,"") GUiCtrlSetData($inputComputerName,"") GUiCtrlSetData($inputName,"") GUiCtrlSetData($inputLotusPW,"") GUiCtrlSetData($inputPhoneNo,"") GUiCtrlSetData($inputPW,"") GUiCtrlSetData($inputDate,"") GUiCtrlSetData($inputLocation,"") GUiCtrlSetData($inputSerialNo,"") $DocumentsProcessed = False EndFunc I have attached my project to the post. New Hire Imaging Checklist Input Utility.zip Here is a screen shot of the details from the AV. Again everything is fine until I click the button in my GUI that calls the FileSaveDialog function. (This is on the settings page and logging must be enabled in order for the "..." button to be opened)
-
Familiarize yourself with Koda Form Designer, available with the full version of AutoIt Full Installation and the AutoIt Script Editor.(Customised version of SciTE with lots of additional coding tools for AutoIt) https://www.autoitscript.com/site/autoit/downloads/ Koda will let you create a form assign handles and generate the code for you and you just paste it into your script. Assign handles to your buttons and include a case statement in your While Loop for your button. Assign a function to that button. Also the help file has lots of example code for the GUI stuff.
-
I got it to work, but you have to use the FQDN of the print server i.e \\Servername.domain.com\Printer name.
-
This still does not work. I have used the share name and the path to the network printer i.e \\Servername\Printer
-
Input masks (for GUI dynamic input validation)
Kaimberex replied to GreenCan's topic in AutoIt Example Scripts
When running the example code I am getting this error. "C:\Manual\Development\AutoIt\Include\_inputmask.au3"(91,107) : error: _Iif(): undefined function. If StringLen($Read_Input) - StringInStr($Read_Input, "-") - _Iif(StringInStr($Read_Input, "."), 1, 0) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^- 55 replies
-
I was able to get it to work another way for now I will update to new version and let you know. I do however have a question about _PrintMgr_SetDefaultPrinter. This function only seems to work on a Local printer not a network installed printer. I am trying to set the below printer as a default and it returns 0 when setting the printer as default. I can get it to return 1 on locally installed printers just not network printers. I have tried using the FQDN of the printer. I have also just tried the ShareName. Neither works.
-
I am using the below example script and this is what error returns: #Include <Array.au3> $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) "C:\AutoIt\Include\PrintMgr.au3" (206) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $aRet[$iCount] = $oPrinter.Name ^ ERROR
-
Thanks I was thinking that may have been the reason. I was just using the printer name I was not using the FQDN of the printer.
-
I am trying to print an Excel worksheet using the Excel UDF. I tried looking through the forums to find my answer but couldn't find my exact issue. I can get it to print to the default printer just fine. However when I try to tell the function what printer to use it still prints to my default printer. Here is a snippet of my code. I just want to make sure I am doing this correctly. Any help is appreciated! Thanks! $oExcelChecklist = _Excel_Open(Default, Default, Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $sFilePathChecklist = @ScriptDir & "\Documents\New Hire Checklist.xlsx" $workbookChecklist = _Excel_BookOpen($oExcelChecklist, $sFilePathChecklist) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $msgboxPrint = MsgBox(36,"Print","Would you like to print the Quick Guide and Checklist?",0) switch $msgboxPrint case 6 ;YES _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet,Default,"SecureColor",Default,Default,Default,Default,Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 2", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 2", "Active Worksheet successfully printed.") case 7 ;NO endswitch Secure Color is the name of the printer I want to print to but it still prints to the default printer I have set in the OS.
-
You my friend are a godsend. That worked perfectly!
-
I am going to try to modify the UDF first and if that does not work then I will downgrade. I am still looking for a link to the modified code but haven't found it yet. If you have a link to an existing thread that would be appreciated! Thanks for your help I love your UDFs! I have used many of them and they are so nice.
-
Thanks I literally just found your response in another thread. I will try updating my autoit version.
-
Let me know if I should open a new thread for this but it is still regarding the ExcelUDF. I am trying to use the _Excel_RangeFind() function and it is returning an error. for now I am just using the example from the help file. Console returns this error on the Example Script #include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object and open an example workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel1.xls") If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error opening workbook '" & @ScriptDir & "\Extras\_Excel1.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; ***************************************************************************** ; Find all occurrences of value "37000" (partial match) ; ***************************************************************************** Local $aResult = _Excel_RangeFind($oWorkbook, "37000") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example 1", "Error searching the range." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example 1", "Find all occurrences of value '37000' (partial match)." & @CRLF & "Data successfully searched.") _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") Console Output: "C:\Program Files (x86)\AutoIt3\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR
-
Yeah if I don't use the invisible parameter on the _Excel_BookOpen function I just use the invisible parameter on _ExcelOpen(False) it works as intended. and lets me open the workbook in windows explorer to verify the data was entered and the workbook is visible. The function also works a second time. Local $oExcel = _Excel_Open(False) ;this makes it invisible If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sFilePath = @ScriptDir & "\ComputerName.xls" If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $workbook = _Excel_BookOpen($oExcel, $sFilePath);no need to use additional parameters, parameters are using default values. Local $aArray2D[1][5] = [[$Serial, $ComputerName, $Domain, $Username, $Password]] _Excel_RangeInsert($workbook.activesheet, "A2:E2", $xlShiftDown) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error inserting to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbook, $workbook.Activesheet, $aArray2D, "A2") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookSave($workbook) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookClose($workbook) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error closing workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel)
-
think its working now as I did not use any additional parameters on _ExcelBookOpen Local $oExcel = _Excel_Open(False) ;this makes it invisible If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sFilePath = @ScriptDir & "\ComputerName.xls" If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $workbook = _Excel_BookOpen($oExcel, $sFilePath);no need to use additional parameters, parameters are using default values. Local $aArray2D[1][5] = [[$Serial, $ComputerName, $Domain, $Username, $Password]] _Excel_RangeInsert($workbook.activesheet, "A2:E2", $xlShiftDown) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error inserting to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($workbook, $workbook.Activesheet, $aArray2D, "A2") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookSave($workbook) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookClose($workbook) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Test", "Error closing workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel)
-
its always the simple things. I used Local $oExcel = _Excel_Open(False) to make it not visible and I also used Local $workbook = _Excel_BookOpen($oExcel, $sFilePath,Default,True,Default,Default,Default) and it works the first time but a second try causes it to fail. No error from the script theres just an error on line 227 in Excel.au3 $oExcel.Windows($oWorkbook.Name).Visible = $bVisible This is the console output: "C:\PROGRA~2\AutoIt3\Include\Excel.au3" (227) : ==> Variable must be of type "Object".: $oExcel.Windows($oWorkbook.Name).Visible = $bVisible $oExcel.Windows($oWorkbook.Name)^ ERROR The second set of data is never entered into the workbook and excel is hung in memory. If I close Excel from memory and then run script again it works the first try but any other attempts cause it to fail with the issues above. Its not the end of the world if the users see the workbook opening I was just hoping to make it invisible to the technician who will be using this application. If I just use Local $oExcel = _Excel_Open() and Local $workbook = _Excel_BookOpen($oExcel, $sFilePath) Everything works as intended. Like I said not the end of the world.
-
I would like everything to run behind the scenes without making the excel visible during the data entry; however when I make it not visible and save it, when I go to open it in windows explorer the document will not show the workbook it is still not visible.
-
that seemed to work by adding in more error checking. I removed the sleep calls from the original snippet and updated the error checking and that works. I think my original issue was I was closing excel without closing the book and it was still hung up in memory. After adding the excel book close function it works after repeated attempts. Only difference is I am on Autoit Version 3.3.14.2 not sure if that makes a difference.
-
I kept having issues after the second time running it wouldn't close the previous instance and write the new data. I put some small pauses in there and it seems to work now. Local $oExcel = _Excel_Open();False,False,Default,Default,True) Local $sFilePath = @ScriptDir & "\ComputerName.xls" Local $workbook = _Excel_BookOpen($oExcel, $sFilePath) Local $aArray2D[1][5] = [[$Serial, $ComputerName, $Domain, $Username, $Password]] _Excel_RangeInsert($workbook.activesheet, "A2:E2", $xlShiftDown) Sleep(500) _Excel_RangeWrite($workbook, $workbook.Activesheet, $aArray2D, "A2") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 3", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Sleep(500) _Excel_BookSave($workbook) Sleep(500) _Excel_BookClose($workbook) Sleep(500) _Excel_Close($oExcel)
-
Office 2010