Jump to content

Paste clipboard into Excel as new row


Go to solution Solved by srousskikh,

Recommended Posts

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 post
Share on other sites

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 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
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 post
Share on other sites
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 post
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...