detrauti Posted March 6, 2017 Posted March 6, 2017 Hi Everyone, I am a beginner and I am currently learning and practicing what Autoit can do, so kindly pardon if it sound's silly. What I want to do: 1.creat an excel file 2.entered some information 3.safed it with a certain name, 4.closed the file and reopen it 5. enter information in the renamed file ---> what do I have to write for the parameter: $oWorkbook to acces my workbook? Thank you for helping me
detrauti Posted March 6, 2017 Author Posted March 6, 2017 to get a better understanding see the screenshot:
water Posted March 6, 2017 Posted March 6, 2017 Simple answer is: Do not close the workbook if you still want to work with it My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
detrauti Posted March 6, 2017 Author Posted March 6, 2017 :-P thank you for the quick answer and I agree but only as the description of my problem is not that good. Imagine to open an existing workbook called hello world. How can I (example) write some information in a certain cell?
water Posted March 6, 2017 Posted March 6, 2017 Where do you set variable $workbook? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
detrauti Posted March 6, 2017 Author Posted March 6, 2017 okay thank you for this hint! As I mentioned these are my first steps after working though: "Program on Windows Using FREE Tools". So the solution was: $WorkbookToWriteIn=_Excel_BookOpen($oExcel,@ScriptDir&"\examplewb.xlsx") ;open the workbook and define it as a varaible ($WorkbookToWriteIn) Sleep(2000) Beep(500, 1000) _Excel_RangeWrite($WorkbookToWriteIn,1,"Hello world!","A11")
water Posted March 6, 2017 Posted March 6, 2017 (edited) From the error message in post #4 I assume you want to write a new row each time you open the workbook. If this is true then I suggest to have a look at the wiki. It explains how to work with ranges in Excel. You would need something like "UsedRange.Rows.Count + 1" Edited March 6, 2017 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Subz Posted March 6, 2017 Posted March 6, 2017 As water mentioned: #include <Excel.au3> ;~ Read Only File Local $sReadFile = @ScriptDir & "\ReadFile.xlsx" ;~ Save File Name Local $sSaveFile = @ScriptDir & "\SaveFile.xlsx" ;~ Create Array Local $aPeople[3][2] = [["John",34],["Steve",23],["Bob",41]] ;~ Open Excel $oExcel = _Excel_Open() ;~ Open ReadFile.xlsx as Read Only $oWorkBook = _Excel_BookOpen($oExcel, $sReadFile, True) ;~ Write Array to Excel starting at A1 _Excel_RangeWrite($oWorkBook, $oWorkBook.ActiveSheet, $aPeople) ;~ Save WorkBook _Excel_BookSaveAs($oWorkBook, $sSaveFile, Default, True) ;~ Rewrite $aPeople to next empty row in Cell A _Excel_RangeWrite($oWorkBook, $oWorkBook.ActiveSheet, $aPeople, "A" & $oWorkBook.ActiveSheet.UsedRange.Rows.Count + 1) _Excel_BookSave($oWorkBook) detrauti 1
water Posted March 6, 2017 Posted March 6, 2017 As you can see in the code posted by Subz he uses a prefix for variables. So you always know what to expect when using a variable (a string, an object, an integer ...). More Good Coding Practices are described here. detrauti 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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