Jump to content

Recommended Posts

Posted (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😍


 

#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 by Jos
added codebox
Posted
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
Posted (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 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.
  :)

Posted (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 by Jos
source removed
  • Developers
Posted (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 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.
  :)

Posted
#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
Posted (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 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.
  :)

Posted
2 minutes ago, Jos said:

 

當您打開它時,您仍然沒有隱藏excel。檢查幫助文件中的正確參數!

 

#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

  • Melba23 changed the title to Excel
Posted (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 by Subz
Posted
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

Posted
#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

1.png.1119c532add9b30bcec9fac87a1b7dab.png
How do I save it correctly?

By the way, EXCEL is no longer visible: D
Thank you 😁

Posted
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.

 

#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)

1.png.d8de7152c8a0ff08f9432d5aec57a8ab.png

  • Moderators
Posted

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

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (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 by Nine
Posted

@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

#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)

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...