MrLee301 Posted January 23, 2024 Posted January 23, 2024 (edited) Hi everyone,I'd like to check the comment on a specify cell exist or not, but it's not successful with below error, it took 2 day for searching but not found, anybody can help this problem, thanks for advance. ###########################Code############## #include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object Local $oAppl = _Excel_Open() If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook = @ScriptDir & "\Book1.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook, Default, Default, True) $check = $oWorkbook.Worksheets(2).Range("J10").Comment.Visible If not $check Then ConsoleWrite("Cell J10's comment not exist") Else ConsoleWrite("Cell J10's comment not exist") EndIf ConsoleWrite($check) ########### OUTPUT ######### : ==> The requested action with this object has failed.: $check = $oWorkbook.Worksheets(2).Range("J10").Comment.Visible $check = $oWorkbook.Worksheets(2).Range("J10").Comment^ ERROR Edited January 23, 2024 by Jos added codebox
ioa747 Posted January 23, 2024 Posted January 23, 2024 #include <Excel.au3> #include <MsgBoxConstants.au3> Local $oExcel, $oWorkbook $oExcel = _Excel_Open() ;~ $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test1.xlsx") $oWorkbook = _Excel_BookNew($oExcel) Local $iStep = 1, $sTip[6][2] $sTip[0][0] = 5 For $i = 1 To $sTip[0][0] $sTip[$i][0] = "A" & $iStep $sTip[$i][1] = "Tip no (" & $i & ")" $oWorkbook.Worksheets(1).Range($sTip[$i][0]).AddComment.Text($sTip[$i][1]) $oWorkbook.Worksheets(1).Comments($i).Visible = True $iStep += 3 Sleep(500) Next Sleep(2000) ConsoleWrite("Comments count = " & $oWorkbook.Worksheets(1).Comments.count & @CRLF) For $i = 1 To $sTip[0][0] $oWorkbook.Worksheets(1).Comments($i).Visible = False Sleep(500) Next Sleep(2000) For $i = 1 To $sTip[0][0] $oWorkbook.Worksheets(1).Range($sTip[$i][0]).ClearComments Sleep(500) Next I know that I know nothing
water Posted January 23, 2024 Posted January 23, 2024 $oWorkbook.Worksheets(1).Range("B2").Specialcells($xlCellTypeComments) ; -4144 Cells containing notes. Returns a Range holding all cells with comments. This way you can check for a comment of a single cell as well. 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
MrLee301 Posted January 23, 2024 Author Posted January 23, 2024 Test1.xlsx Sorry, i need to insert my excel file to make it clear, the user create that file and add comment manually as below picture, i may check comment exist on cells: A1,A2,A3,A4... -> get content and assign to an array like this: "content | comment" ########### Local Array aArray[10] aArray[0]="|"; read from (A1) aArray[1]="abc1|"; read from (A2) aArray[2]="abc2|"; read from (A3) aArray[3]="abc3|comment1"; read from (A4) .......... Thank you @ioa747 and @water but it's not solved this matter yet.
Solution Nine Posted January 23, 2024 Solution Posted January 23, 2024 (edited) Try this : #include <Excel.au3> Local $oExcel = _Excel_Open() Local $oWorkBook = _Excel_BookOpen($oExcel, @ScriptDir & "\Test1.xlsx") Local $oRange = $oWorkBook.Sheets(1).Range("A1:A8") Local $aList[$oRange.count], $i = 0, $oComment For $oCell in $oRange $aList[$i] = $oCell.value $oComment = $oCell.comment $aList[$i] &= "|" & (IsObj($oComment) ? $oComment.text : "") $i += 1 Next _ArrayDisplay($aList) Edited January 23, 2024 by Nine MrLee301 and ioa747 1 1 “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
MrLee301 Posted January 23, 2024 Author Posted January 23, 2024 IsObj($oComment) -> that's the point, you save my day, thank you. @Nine
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