srousskikh Posted August 15, 2021 Share Posted August 15, 2021 Hi everyone! I have a list of URLs to be copied into an active (open) Excel workbook each as new row in column A. I was able to attach to the workbook and get number of rows as follow: #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> ; Create application object and open an example workbook Local $sWorkbook = "d:\DOCUMENTS\Surveys\_surveys_paneldirector.xlsx" Local $oExcel = _Excel_Open() If @error Then Exit Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) If @error Then _Excel_Close($oExcel) Exit EndIf ; Attach to the first Workbook where the file path matches $oWorkbook = _Excel_BookAttach($sWorkbook) If @error Then Exit $oRange = $oExcel.ActiveSheet.Range("A:A") MsgBox(4096, "Excel Count Non-Blank Cells", $oExcel.WorksheetFunction.CountA($oRange)) Will you please help me with the remaining part of the code (to paste each URL from clipboard into new Excel row)? Link to comment Share on other sites More sharing options...
srousskikh Posted August 15, 2021 Author Share Posted August 15, 2021 I copy URLs manually one by one, not in bulk Link to comment Share on other sites More sharing options...
srousskikh Posted August 15, 2021 Author Share Posted August 15, 2021 I have also found the code to paste clipboard into fixed cell: $oExcel.Application.ActiveSheet.Range("A1").Select $oExcel.Selection.Paste How to paste it as new row? Link to comment Share on other sites More sharing options...
JockoDundee Posted August 15, 2021 Share Posted August 15, 2021 Global $iNextNewRow = $oExcel.ActiveSheet.UsedRange.Rows.Count + 1 $oExcel.Application.ActiveSheet.Range("A" & $iNextNewRow).Select $oExcel.Selection.Paste Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
srousskikh Posted August 15, 2021 Author Share Posted August 15, 2021 Many thanks for quick reply! Now it selects new row in A column but throws error "The requested action with object has failed". There is a plain text in the clipboard, Excel from Office 365. Link to comment Share on other sites More sharing options...
water Posted August 15, 2021 Share Posted August 15, 2021 You could use the Excel UDF that comes with AutoIt. You could either use _Excel_RangeCopyPaste to write the content of the clipboard to cell or write all URL to an array and use _Excel_RangeWrite to write all URLs in one go to tjhe 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 Link to comment Share on other sites More sharing options...
srousskikh Posted August 15, 2021 Author Share Posted August 15, 2021 18 minutes ago, water said: You could use the Excel UDF that comes with AutoIt. You could either use _Excel_RangeCopyPaste to write the content of the clipboard to cell or write all URL to an array and use _Excel_RangeWrite to write all URLs in one go to tjhe workbook. Many thanks! I have already tried to paste it into fixed cell as follows: _Excel_RangeCopyPaste($oExcel.ActiveSheet, Default, "A41") It selects the cell but doesn't actually paste the text form clipboard Link to comment Share on other sites More sharing options...
srousskikh Posted August 15, 2021 Author Share Posted August 15, 2021 42 minutes ago, JockoDundee said: Global $iNextNewRow = $oExcel.ActiveSheet.UsedRange.Rows.Count + 1 $oExcel.Application.ActiveSheet.Range("A" & $iNextNewRow).Select $oExcel.Selection.Paste Many thanks! First two lines work well and the scripts selects new row. And this: $oExcel.Selection.Paste throws the error mentioned above. Just unable to paste from the clipboard for some reason Link to comment Share on other sites More sharing options...
Solution srousskikh Posted August 15, 2021 Author Solution Share Posted August 15, 2021 Thanks everyone! I have made it work this way: Global $iNextNewRow = $oExcel.ActiveSheet.UsedRange.Rows.Count + 1 $oExcel.ActiveSheet.Range("A" & $iNextNewRow).Select $oExcel.ActiveSheet.Paste Skysnake 1 Link to comment Share on other sites More sharing options...
water Posted August 15, 2021 Share Posted August 15, 2021 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 Link to comment Share on other sites More sharing options...
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