msmith83100 Posted April 16, 2019 Posted April 16, 2019 Hello all! I've been searching the help files and forums, maybe I've missed it but I'm looking for a place to start on pasting from an array I put onto the clipboard. My code has the user select the cell(s) that they want put into the array, which copies just fine. I've even got a message box to display the data to confirm. But I want to be able to paste into ANY program from the cursor point while tabbing between elements... Anyone able to help me with a decent starting point? Here's what I have so far... Local $vRange =0 Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\TESting.xlsx") ; Read the data of a cell range on specified workbook ;Local $aResult = _Excel_RangeRead($oWorkbook, 1, "A3:L30", 2) MsgBox($MB_SYSTEMMODAL, "Info", "Select cells in Excel then click OK") Local $vRange = $oExcel.Selection.Address ;Displays message box to select range of data selected MsgBox($MB_SYSTEMMODAL, "Title", "Range value" & $vRange & "selected") Local $aResult = _Excel_RangeRead($oWorkbook, 1, $vRange, 2) ;Displays messagebox, instructing user to go to window to start pasting data from array If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Data successfully read." & @CRLF & "Please click 'OK' to paste the data from of cells " & $vRange &" of sheet 1.") ;get highlighted window and paste data from array with tab between elements ;Displays data inside selected cells _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeRead Example 2 - Cells A1:C1 of sheet 2")
Nine Posted April 16, 2019 Posted April 16, 2019 Maybe something like as simple as this ? For $i = 0 to Ubound($aResult)-1 ClipPut ($aResult[$i]) Send ("^v") Sleep (150) Send ("{TAB}") Sleep (150) Next “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
msmith83100 Posted April 16, 2019 Author Posted April 16, 2019 subscript dimension exceeded. Kind of what I figured, I'm trying to paste from an Array. Shouldn't there be a loop?
msmith83100 Posted April 16, 2019 Author Posted April 16, 2019 not what I should have said - there's a loop. But gives a subscript range dimension exceeded... I see tons of fill an array, read an array examples... but not for pasting... Any help on elaborating?
msmith83100 Posted April 16, 2019 Author Posted April 16, 2019 well it should also be Clipget no Clipput.. I also found this... but for some reason everything past MsgBox(xxx) gets put into message boxes... it's like it's not seeing the closing argument... #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Array.au3> Local $vRange =0 Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Test.xlsx") ; Read the data of a cell range on specified workbook ;Local $aResult = _Excel_RangeRead($oWorkbook, 1, "A3:L30", 2) MsgBox($MB_SYSTEMMODAL, "Info", "Select cells in Excel then click OK") Local $vRange = $oExcel.Selection.Address ;Displays message box to select range of data selected MsgBox($MB_SYSTEMMODAL, "Title", "Range value" & $vRange & "selected") Local $aResult = _Excel_RangeRead($oWorkbook, 1, $vRange, 2) ;Displays messagebox, instructing user to go to window to start pasting data from array If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Data successfully read." & @CRLF & "Please click 'OK' to paste the data from of cells " & $vRange &" of sheet 1.") ;this area here also gets put into message boxes... $content = ClipGet() $array = StringSplit(StringStripCR($content), @LF) If Not @error Then For $i = 1 To $array[0] MsgBox(0, '', $array[$i]) Next EndIf ;Displays data inside selected cells _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeRead Example 2 - Cells A1:C1 of sheet 2")
Nine Posted April 16, 2019 Posted April 16, 2019 Ok you are getting a bit excessive. I told you how to do it. So calm down, and read help file. And try to understand what you are doing... “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
msmith83100 Posted April 16, 2019 Author Posted April 16, 2019 @Nine I appreciate your help, but I've tried your fix, which it seems like you questioned when putting it out there. You also had ClipPut which is to put into an array, I already have it in an array. I'm trying to understand the printing (output) of the array. I've looked for about 6 hours today just trying to find out how to print an array - hence the seeming of frustration. Not being able to edit a post makes it look worse, cause you have to make a new post. I've read help files and googled my brains out.
Danp2 Posted April 16, 2019 Posted April 16, 2019 2 hours ago, msmith83100 said: well it should also be Clipget no Clipput This is wrong. You stated that you want to paste text into another program, so you need to use Clipput to load the text onto the clipboard. 3 hours ago, msmith83100 said: subscript dimension exceeded This should have worked at posted by @Nine. Perhaps you didn't just copy/paste it into your script. <shrug> Latest Webdriver UDF Release Webdriver Wiki FAQs
Subz Posted April 16, 2019 Posted April 16, 2019 (edited) Nine solution is only for 1d array, you would need to use Ubound($aResult, 2) to access 2d array info (see my example array below). Personally I would use _ArrayToString() something like: #include <Array.au3> Global $g_aArray[10][10] For $i = 0 To Ubound($g_aArray) - 1 For $j = 0 To Ubound($g_aArray, 2) - 1 $g_aArray[$i][$j] = Chr(Random(65, 122, 1)) Next Next _ArrayDisplay($g_aArray) Global $g_sArray = _ArrayToString($g_aArray, @TAB) ClipPut($g_sArray) MsgBox(4096, "Example Table", "The following data has been captured to clipboard." & @CRLF & @CRLF & $g_sArray) Edited April 16, 2019 by Subz Forgot to post Ubound code.
msmith83100 Posted April 17, 2019 Author Posted April 17, 2019 13 hours ago, Danp2 said: This is wrong. You stated that you want to paste text into another program, so you need to use Clipput to load the text onto the clipboard. This should have worked at posted by @Nine. Perhaps you didn't just copy/paste it into your script. <shrug> Nope I copied and pasted.. Like I said, I already have it loading into the clipboard, thanks!
msmith83100 Posted April 17, 2019 Author Posted April 17, 2019 13 hours ago, Subz said: Nine solution is only for 1d array, you would need to use Ubound($aResult, 2) to access 2d array info (see my example array below). Personally I would use _ArrayToString() something like: #include <Array.au3> Global $g_aArray[10][10] For $i = 0 To Ubound($g_aArray) - 1 For $j = 0 To Ubound($g_aArray, 2) - 1 $g_aArray[$i][$j] = Chr(Random(65, 122, 1)) Next Next _ArrayDisplay($g_aArray) Global $g_sArray = _ArrayToString($g_aArray, @TAB) ClipPut($g_sArray) MsgBox(4096, "Example Table", "The following data has been captured to clipboard." & @CRLF & @CRLF & $g_sArray) @Subz Thank you for your input... but that's a fixed array. I thought about going that route, but as it sits; with this script I can select any amount of data and it will copy it into the clipboard. I thought about doing a fixed array for say 50 entries, but that's not always needed. If I only want to copy 10 items and paste, it's a little overkill and it might cause issues on pasting... I think I might go the route of selecting data from one row to copy into the clipboard. But basically If I can print a 1D (row) array of information I'm good. I don't want it to paste to a MSGbox, I've already got that.
Subz Posted April 17, 2019 Posted April 17, 2019 Don't know what you mean by fixed array, the array is just an example of what could be returned by _Excel_RangeRead, the only part of the script above which is relevant to you, is everything below _ArrayDisplay($g_aArray). You could also use _Excel_RangeCopyPaste, if you leave $vTargetRange to default, the data would be copied directly into the clipboard and will retain formatting etc..
Moderators JLogan3o13 Posted April 17, 2019 Moderators Posted April 17, 2019 On 4/16/2019 at 6:02 PM, Nine said: Ok you are getting a bit excessive. I told you how to do it. So calm down, and read help file. And try to understand what you are doing... Perhaps take your own advice and breathe a bit. New members cannot edit their posts, so after-thoughts are generally another post. The OP is simply trying to explain in detail what he is trying to do. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Nine Posted April 17, 2019 Posted April 17, 2019 1 minute ago, JLogan3o13 said: Perhaps take your own advice and breathe a bit I breathe a lot, probably more than you do. So you are the boss, do what you have to do... “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
msmith83100 Posted April 18, 2019 Author Posted April 18, 2019 17 hours ago, Nine said: I breathe a lot, probably more than you do. So you are the boss, do what you have to do... @JLogan3o13 This a great way to make new people welcome, don't you think? :)
Developers Jos Posted April 18, 2019 Developers Posted April 18, 2019 17 hours ago, Nine said: I breathe a lot, probably more than you do. So you are the boss, do what you have to do... Why this attitude suddenly, no need for that so please don't show that around here. Thanks, 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.
Moderators JLogan3o13 Posted April 18, 2019 Moderators Posted April 18, 2019 @msmith83100 @Nine and I spoke in PM, chalk it up to miscommunication as can happen on the forum. Let us move on to getting your question answered. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
msmith83100 Posted April 18, 2019 Author Posted April 18, 2019 @JLogan3o13 Sounds great! I've got everything working except for the pasting of whats on the clipboard., which is an array. I can paste it to a message box just fine, but getting it to "paste" in general is the issue. I've been using @Nine Ubound with ClipGet, but to no avail. It seems the simplest and I guess should work, but I still get the subscript range dimension exceeded error... As my code sits, I can go into Excel and copy any number of cells (1 to 3 rows 1 to 10 columns) and it will paste that data into a message box. I don't want a message box, I just want it to paste where ever the cursor is, tab, paste the next cell contents, tab, paste...etc. Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Test.xlsx") MsgBox($MB_SYSTEMMODAL, "Info", "Select cells in Excel then click OK") Local $vRange = $oExcel.Selection.Address ;Displays message box to select range of data selected MsgBox($MB_SYSTEMMODAL, "Title", "Range value" & $vRange & "selected") Local $aResult = _Excel_RangeRead($oWorkbook, 1, $vRange, 2) ;Displays messagebox, instructing user to go to window to start pasting data from array If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Data successfully read." & @CRLF & "Please click 'OK' to paste the data from of cells " & $vRange & " of sheet 1.") For $i = 0 to Ubound($aResult)-1 ClipGet ($aResult[$i]) Send ("^v") Sleep (150) Send ("{TAB}") Sleep (150) Next ;Displays data inside selected cells _ArrayDisplay($aResult)
Danp2 Posted April 18, 2019 Posted April 18, 2019 Maybe I'm just being dense, but it still seems like you are using ClipGet when you should be using ClipPut. Hint: ClipGet doesn't take any parameters Latest Webdriver UDF Release Webdriver Wiki FAQs
msmith83100 Posted April 18, 2019 Author Posted April 18, 2019 @Danp2 That's why I don't get it when I'm told to use ClipPut... From the help file ClipPut writes text to the Clipboard...I already have it there I need to paste it off the clipboard. Didn't know Clipget wouldn't take parameters... it didn't have any in helpfile...I was just hoping it might. thanks though! Even if I use CLipPut, I still get the subscript range dimension exceeded error... Next? LOL
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