gto70070 Posted March 17, 2020 Posted March 17, 2020 (edited) This is my script Can I make excel invisible? Just like using the [FileOpen] function and the [FileWriteLine] function If there is a way you can tell me I would be grateful😍 expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) Global $Input1 = GUICtrlCreateInput("", 56, 32, 121, 21) Global $Input2 = GUICtrlCreateInput("", 56, 72, 121, 21) Global $Input3 = GUICtrlCreateInput("", 56, 112, 121, 21) Global $Input4 = GUICtrlCreateInput("", 56, 152, 121, 21) Global $Input5 = GUICtrlCreateInput("", 56, 192, 121, 21) $Button1 = GUICtrlCreateButton("Click", 56, 232, 123, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MINE() EndSwitch WEnd Func MINE() Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf $Input11 = GUICtrlRead($Input1) $Input22 = GUICtrlRead($Input2) $Input33 = GUICtrlRead($Input3) $Input44 = GUICtrlRead($Input4) $Input55 = GUICtrlRead($Input5) $N = 1 For $counter = 1 To 20 Step 1 _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input11,"A"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input22,"B"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input33,"C"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input44,"D"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input55,"E"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $N = $N + 1 Next EndFunc ; Create application object and create a new workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Write a string with a line break to the active sheet in the active workbook _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Test" & @CRLF & "String","B1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Edited March 17, 2020 by Jos added codebox
Subz Posted March 17, 2020 Posted March 17, 2020 See the first parameter of _Excel_Open function i.e. $bVisible = False
gto70070 Posted March 17, 2020 Author Posted March 17, 2020 13 minutes ago, Subz said: 參見_Excel_Open函數的第一個參數,即$ bVisible = False #include <Excel.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) Global $Input1 = GUICtrlCreateInput("", 56, 32, 121, 21) Global $Input2 = GUICtrlCreateInput("", 56, 72, 121, 21) Global $Input3 = GUICtrlCreateInput("", 56, 112, 121, 21) Global $Input4 = GUICtrlCreateInput("", 56, 152, 121, 21) Global $Input5 = GUICtrlCreateInput("", 56, 192, 121, 21) $Button1 = GUICtrlCreateButton("Click", 56, 232, 123, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MINE() EndSwitch WEnd Func MINE() Local $oExcel = _Excel_Open() $oWorkbook = _Excel_BookOpen ( $oExcel, "C:\Users\gto70\Desktop\excel.xlsx" , 0 , 0 ) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf $Input11 = GUICtrlRead($Input1) $Input22 = GUICtrlRead($Input2) $Input33 = GUICtrlRead($Input3) $Input44 = GUICtrlRead($Input4) $Input55 = GUICtrlRead($Input5) $N = 1 For $counter = 1 To 20 Step 1 _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input11,"A"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input22,"B"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input33,"C"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input44,"D"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input55,"E"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $N = $N + 1 Next EndFunc ; Create application object and create a new workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Write a string with a line break to the active sheet in the active workbook _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Test" & @CRLF & "String","B1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Thank you for your reply This is the script I changed But the excel window is still visible. Is there any other error? Thanks again for your reply😍
Developers Jos Posted March 17, 2020 Developers Posted March 17, 2020 (edited) 8 minutes ago, gto70070 said: This is the script I changed Please use the codebox for AutoIt3 Sourcecode as I shown in the first post! Also read the helpfile so you understand how to make the change to _Excel_Open() , not _Excel_BookOpen ()! Edited March 17, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
gto70070 Posted March 17, 2020 Author Posted March 17, 2020 (edited) 7 minutes ago, Jos said: 如我在第一篇文章中所示,請使用AutoIt3源代碼的代碼箱! 另請閱讀幫助文件,以便您了解如何對_ExcelOpen()而不是_Excel_BookOpen ()進行更改 ! Thank you for your reply This is my modified script, I think he can help (hide excel) I'm trying to save it Thanks Autoit for the forum, always warming Edited March 17, 2020 by Jos source removed
Developers Jos Posted March 17, 2020 Developers Posted March 17, 2020 (edited) 3 minutes ago, gto70070 said: Thank you for your reply again Use a CodeBox for posting sourcecode! ... code removed so try again! 3 minutes ago, gto70070 said: Thanks Autoit for the forum, always warming That is because you have Chinese characters in the post, so it needs to be approved by a Mod. So just use English please and do not post translated text in your post! Edited March 17, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
gto70070 Posted March 17, 2020 Author Posted March 17, 2020 expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) Global $Input1 = GUICtrlCreateInput("", 56, 32, 121, 21) Global $Input2 = GUICtrlCreateInput("", 56, 72, 121, 21) Global $Input3 = GUICtrlCreateInput("", 56, 112, 121, 21) Global $Input4 = GUICtrlCreateInput("", 56, 152, 121, 21) Global $Input5 = GUICtrlCreateInput("", 56, 192, 121, 21) $Button1 = GUICtrlCreateButton("Click", 56, 232, 123, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MINE() EndSwitch WEnd Func MINE() ; Create application object or connect to an already running Excel instance Local $oExcel = _Excel_Open() $oWorkbook = _Excel_BookOpen ( $oExcel, "C:\Users\gto70\Desktop\KB系列\KB_ECAuto\excel.xlsx" , 0 , 0 ) If @error Then MsgBox($MB_SYSTEMMODAL, "UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf $Input11 = GUICtrlRead($Input1) $Input22 = GUICtrlRead($Input2) $Input33 = GUICtrlRead($Input3) $Input44 = GUICtrlRead($Input4) $Input55 = GUICtrlRead($Input5) $N = 1 For $counter = 1 To 20 Step 1 _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input11,"A"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input22,"B"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input33,"C"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input44,"D"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input55,"E"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $N = $N + 1 Next _Excel_BookSave ( $oWorkbook ) EndFunc ; Create application object and create a new workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Write a string with a line break to the active sheet in the active workbook _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Test" & @CRLF & "String","B1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) This is my script But after running she will show Error creating the new workbook. error = 2 & extended = 0 How to solve this? Can "_Excel_Open" function open excel with specified path? I don't see related parameters in the help So I use the "_Excel_BookOpen" function instead, thank you for your enlightenment Thanks again Autoit and everyone😘
Developers Jos Posted March 17, 2020 Developers Posted March 17, 2020 (edited) 2 minutes ago, gto70070 said: But after running she will show 2 minutes ago, gto70070 said: Local $oExcel = _Excel_Open() You are still not HIDING excel when you open it. Check the helpfile for the correct parameter! Quote #include <Excel.au3>_Excel_Open ( [$bVisible = True [, $bDisplayAlerts = False [, $bScreenUpdating = True [, $bInteractive = True [, $bForceNew = False]]]]] ) Edited March 17, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
gto70070 Posted March 17, 2020 Author Posted March 17, 2020 2 minutes ago, Jos said: 當您打開它時,您仍然沒有隱藏excel。檢查幫助文件中的正確參數! expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) Global $Input1 = GUICtrlCreateInput("", 56, 32, 121, 21) Global $Input2 = GUICtrlCreateInput("", 56, 72, 121, 21) Global $Input3 = GUICtrlCreateInput("", 56, 112, 121, 21) Global $Input4 = GUICtrlCreateInput("", 56, 152, 121, 21) Global $Input5 = GUICtrlCreateInput("", 56, 192, 121, 21) $Button1 = GUICtrlCreateButton("Click", 56, 232, 123, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MINE() EndSwitch WEnd Func MINE() ; Create application object or connect to an already running Excel instance Local $oExcel = _Excel_Open(0) $oWorkbook = _Excel_BookOpen ( $oExcel, "C:\Users\gto70\Desktop\KB系列\KB_ECAuto\excel.xlsx" , 0 , 0 ) If @error Then MsgBox($MB_SYSTEMMODAL, "UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf $Input11 = GUICtrlRead($Input1) $Input22 = GUICtrlRead($Input2) $Input33 = GUICtrlRead($Input3) $Input44 = GUICtrlRead($Input4) $Input55 = GUICtrlRead($Input5) $N = 1 For $counter = 1 To 20 Step 1 _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input11,"A"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input22,"B"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input33,"C"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input44,"D"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input55,"E"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $N = $N + 1 Next _Excel_BookSave ( $oWorkbook ) EndFunc ; Create application object and create a new workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Write a string with a line break to the active sheet in the active workbook _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Test" & @CRLF & "String","B1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) This is my modified script I add "_Excel_Open" function with parameter 0 But still shows Error creating the new workbook. error = 2 & extended = 0 How do I fix my script? Thank you for your enlightenment
gto70070 Posted March 17, 2020 Author Posted March 17, 2020 How do I open Excel on the specified path. Does anyone give me any tips? thank you very much
Subz Posted March 18, 2020 Posted March 18, 2020 (edited) Your second instance of _Excel_Open() is still set to visible, you also never close the first instance of $oExcel so you're calling it twice, you could use something like: If Not IsObj($oExcel) Then $oExcel = _Excel_Open(False) $oWorkbook = _Excel_BookNew($oExcel) Edited March 18, 2020 by Subz
gto70070 Posted March 18, 2020 Author Posted March 18, 2020 5 hours ago, Subz said: 您的_Excel_Open()的第二個實例仍然設置為可見,您也永遠不會關閉$ oExcel的第一個實例,因此您要調用它兩次,可以使用如下方法: 如果 不是 IsObj($ oExcel ), 則 $ oExcel = _Excel_Open(False) $ oWorkbook = _Excel_BookNew($ oExcel ) How do I use the _Excel_Open () function if I want to open the excel of an existing path? Thank you very much for your reply, I am still learning Autoit
gto70070 Posted March 18, 2020 Author Posted March 18, 2020 expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) Global $Input1 = GUICtrlCreateInput("", 56, 32, 121, 21) Global $Input2 = GUICtrlCreateInput("", 56, 72, 121, 21) Global $Input3 = GUICtrlCreateInput("", 56, 112, 121, 21) Global $Input4 = GUICtrlCreateInput("", 56, 152, 121, 21) Global $Input5 = GUICtrlCreateInput("", 56, 192, 121, 21) $Button1 = GUICtrlCreateButton("Click", 56, 232, 123, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MINE() EndSwitch WEnd Func MINE() @extended = 0 $Input11 = GUICtrlRead($Input1) $Input22 = GUICtrlRead($Input2) $Input33 = GUICtrlRead($Input3) $Input44 = GUICtrlRead($Input4) $Input55 = GUICtrlRead($Input5) Local $oExcel = _Excel_Open(False) If @error Then Exit Local $oBook = _Excel_BookNew($oExcel) If @error Then Exit _Excel_RangeWrite($oBook, $oBook.ActiveSheet, $Input11,"A1") Local $sFilePath = "Coachin2020-03-05.xlsx" _Excel_BookSaveAs($oBook, $sFilePath, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $oBook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) #cs $N = 1 For $counter = 1 To 20 Step 1 _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input11,"A"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input22,"B"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input33,"C"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input44,"D"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input55,"E"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $N = $N + 1 Next _Excel_BookSave ( $oWorkbook ) #CE EndFunc ; Create application object and create a new workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Write a string with a line break to the active sheet in the active workbook _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Test" & @CRLF & "String","B1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) This is my script When I run, he returns the following screen How do I save it correctly? By the way, EXCEL is no longer visible: D Thank you 😁
Nine Posted March 18, 2020 Posted March 18, 2020 You must provide FULL path on the save (same goes with open or any other file manipulation within Excel UDF). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
gto70070 Posted March 18, 2020 Author Posted March 18, 2020 7 minutes ago, Nine said: 您必須在保存時提供FULL 路徑(打開或Excel UDF中的任何其他文件操作都相同)。 @Nine Thank you very much for your reply. I have set the path to the full path. But still returns the same error. expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) Global $Input1 = GUICtrlCreateInput("", 56, 32, 121, 21) Global $Input2 = GUICtrlCreateInput("", 56, 72, 121, 21) Global $Input3 = GUICtrlCreateInput("", 56, 112, 121, 21) Global $Input4 = GUICtrlCreateInput("", 56, 152, 121, 21) Global $Input5 = GUICtrlCreateInput("", 56, 192, 121, 21) $Button1 = GUICtrlCreateButton("Click", 56, 232, 123, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MINE() EndSwitch WEnd Func MINE() @extended = 0 $Input11 = GUICtrlRead($Input1) $Input22 = GUICtrlRead($Input2) $Input33 = GUICtrlRead($Input3) $Input44 = GUICtrlRead($Input4) $Input55 = GUICtrlRead($Input5) Local $oExcel = _Excel_Open(False) If @error Then Exit Local $oBook = _Excel_BookNew($oExcel) If @error Then Exit _Excel_RangeWrite($oBook, $oBook.ActiveSheet, $Input11,"A1") Local $sFilePath = "C:\Coachin2020-03-05.xlsx" _Excel_BookSaveAs($oBook, $sFilePath, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $oBook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) #cs $N = 1 For $counter = 1 To 20 Step 1 _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input11,"A"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input22,"B"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input33,"C"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input44,"D"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input55,"E"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $N = $N + 1 Next _Excel_BookSave ( $oWorkbook ) #CE EndFunc ; Create application object and create a new workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Write a string with a line break to the active sheet in the active workbook _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Test" & @CRLF & "String","B1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Moderators Melba23 Posted March 18, 2020 Moderators Posted March 18, 2020 gto70070, Please stop using the "Quote" button when you reply - not only does is pad the thread but it means the Mods have to manually approve each of your posts as it contains Chinese characters. Please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom. Thanks in advance for your cooperation - because if you do not cooperate you may find your posts are no longer approved. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Nine Posted March 18, 2020 Posted March 18, 2020 (edited) Your code works for me. Maybe you have no rights saving in root directory. Try saving in script folder. do not forget to close excel as it will stay open and hidden. Go into Task Manager and close any Excel process. Local $sFilePath = @ScriptDir & "\Coachin2020-03-05.xlsx" _Excel_BookSaveAs($oBook, $sFilePath, Default, True) If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Error saving workbook" & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close ($oExcel) Try this... Edited March 18, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
gto70070 Posted March 18, 2020 Author Posted March 18, 2020 @Moderators Sorry, I switched to Reply to this topic Thank you for reminding @Nine Awesome! My script is running normally! thank you! The following is my script, hope I can help others in the future expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) Global $Input1 = GUICtrlCreateInput("", 56, 32, 121, 21) Global $Input2 = GUICtrlCreateInput("", 56, 72, 121, 21) Global $Input3 = GUICtrlCreateInput("", 56, 112, 121, 21) Global $Input4 = GUICtrlCreateInput("", 56, 152, 121, 21) Global $Input5 = GUICtrlCreateInput("", 56, 192, 121, 21) $Button1 = GUICtrlCreateButton("Click", 56, 232, 123, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MINE() EndSwitch WEnd Func MINE() @extended = 0 $Input11 = GUICtrlRead($Input1) $Input22 = GUICtrlRead($Input2) $Input33 = GUICtrlRead($Input3) $Input44 = GUICtrlRead($Input4) $Input55 = GUICtrlRead($Input5) Local $oExcel = _Excel_Open(False) If @error Then Exit Local $oBook = _Excel_BookNew($oExcel) If @error Then Exit _Excel_RangeWrite($oBook, $oBook.ActiveSheet, $Input11,"A1") Local $sFilePath = @ScriptDir & "\Coachin2020-03-05.xlsx" _Excel_BookSaveAs($oBook, $sFilePath, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $oBook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close ($oExcel) #cs $N = 1 For $counter = 1 To 20 Step 1 _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input11,"A"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input22,"B"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook, $Input33,"C"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input44,"D"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Input55,"E"&$N) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $N = $N + 1 Next _Excel_BookSave ( $oWorkbook ) #CE EndFunc ; Create application object and create a new workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oExcel) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Write a string with a line break to the active sheet in the active workbook _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Test" & @CRLF & "String","B1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 1", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Nine Posted March 19, 2020 Posted March 19, 2020 Those hidden processes can be tricky... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now