qwiqshot Posted August 5, 2016 Share Posted August 5, 2016 Is there some way to copy data from a cell (Someones first and last name) then re arrange it place a comma between them and then paste it elsewhere like into notepad? For example. Cell A2 contents read Gerry Folks - Grab this data, re arrange to read Folks, Gerry - then be able to paste it into, say Notepad An ex co worker did this in excel VB but I am working to eliminate their code by using Autoit This was his VB code =LEFT(A2,FIND(" ",A2,1)-1) =RIGHT(A2,LEN(A2)-FIND(" ",A2,1)) =CONCATENATE(J18,", ",I18) Link to comment Share on other sites More sharing options...
water Posted August 6, 2016 Share Posted August 6, 2016 AutoIt comes with an Excel UDF. Use function _Excel_RangeRead to read the cells value into a variable which you then can rearrange. 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...
l3ill Posted August 6, 2016 Share Posted August 6, 2016 had some time to kill... Step. 2 6 hours ago, water said: a variable which you then can rearrange. $sVar = "Gerry Folks" $aNewstring = StringSplit($sVar, " ") $sNewstring = $aNewstring[2] & ", " & $aNewstring[1] MsgBox(0, "", $sNewstring) My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
qwiqshot Posted August 16, 2016 Author Share Posted August 16, 2016 Thank you both. Work got busy and had not had time to reply until now. Link to comment Share on other sites More sharing options...
qwiqshot Posted September 14, 2016 Author Share Posted September 14, 2016 Hi again all I've been tinkering around trying to get this to work and I am not understanding how it works. I have what I think should work, but it is not. #include <Excel.au3> Func getname() Local $oExcel = _Excel_Open() Local $sResult = _Excel_RangeRead ($oExcel.Worksheets("Calculations"), "A3") $aNewstring = StringSplit($sResult, " ") $sNewstring = $aNewstring[2] & ", " & $aNewstring[1] EndFunc I have attached a small screenshot showing the names of a few tabs on the spreadsheet in case it helps solve my issue. I run the function, then I am opening a notepad and pasting any data that has been captured. I am not getting the data from cell A3 on the Calculations sheet. Please smack me in the right direction. Link to comment Share on other sites More sharing options...
water Posted September 14, 2016 Share Posted September 14, 2016 You either need to open a workbook using _Excel_BookOpen or connect to an already open workbook by using _Excel_BookAttach. 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...
qwiqshot Posted September 14, 2016 Author Share Posted September 14, 2016 (edited) Is this what your saying Water? #include <Excel.au3> Func getname() Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookAttach($oExcel) Local $sResult = _Excel_RangeRead ($oExcel.Worksheets("Calculations"), "A3") $aNewstring = StringSplit($sResult, " ") $sNewstring = $aNewstring[2] & ", " & $aNewstring[1] MsgBox(0, "", $sNewstring) EndFunc Edited September 14, 2016 by qwiqshot Link to comment Share on other sites More sharing options...
water Posted September 15, 2016 Share Posted September 15, 2016 No. Please read the help file for _Excel_BookAttach and you will see what's wrong with your statement 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...
qwiqshot Posted September 15, 2016 Author Share Posted September 15, 2016 Hi again Water Does the example change if the spreadsheet were already going to be open? Here is the scenario.... I enter in the details of a pre defined excel form, I go to save the file, at this point I want to grab the name from field A3 of sheet named Calculations, flip the names in reverse (Last name 1st, 1st name last), then add the resulting combination to the file name to be saved. So I would already have the spreadsheet opened and would not require opening anything like in the example (assuming I am reading it correctly, as it shows _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel1.xls" in the example). Link to comment Share on other sites More sharing options...
water Posted September 16, 2016 Share Posted September 16, 2016 Functions _Excel_BookAttach connects the script to an already opened worksheet. So: Yes, you need to this function. Please check the example for _Excel_BookAttach. 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...
qwiqshot Posted September 18, 2016 Author Share Posted September 18, 2016 I tried the help file suggestion and it most definitely gets the data from the cell I want, but it reopens the excel sheet losing the data entered. This is what I used.... #include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object and open an example workbook Local $sWorkbook = "c:\Excel\AsphaltEstimating.xlsm" Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example", "Error opening workbook '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; ***************************************************************************** ; Attach to the first Workbook where the file path matches ; ***************************************************************************** $oWorkbook = _Excel_BookAttach($sWorkbook) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example 1", "Error attaching to '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example 1", "Search by 'filepath':" & @CRLF & @CRLF & "Successfully attached to Workbook '" & $sWorkbook & "'." & @CRLF & @CRLF & "Value of cell A3: " & $oWorkbook.Activesheet.Range("A3").Value) how can I prevent it from closing the sheet losing the data being entered? what I am planning is to save a copy of the excel sheet which is essentially a form with scripts to run calculations to generate contracts, with previously empty fields, now filled with customer specific data entered in, I want to grab the full customer name from A3 to save the file per their name. So if it's closing the file I lose all data entered..... I know this gets old pointing people in the direction of their answers so I apologize for running anyone in the circles you've likely answered a thousand times. Link to comment Share on other sites More sharing options...
water Posted September 18, 2016 Share Posted September 18, 2016 Drop this part of your script: Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example", "Error opening workbook '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf You either need _Excel_BookOpen OR _Excel_BookAttach. qwiqshot 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 Link to comment Share on other sites More sharing options...
qwiqshot Posted September 19, 2016 Author Share Posted September 19, 2016 Water Thank you very much! I would never have thought to drop any of the code. I would have continued trying endless variations until my brain popped. Now i'm excited again! Link to comment Share on other sites More sharing options...
water Posted September 19, 2016 Share Posted September 19, 2016 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...
qwiqshot Posted September 27, 2016 Author Share Posted September 27, 2016 I have another step I am trying to figure out now and have no clue where to start. I have a spreadsheet with 62 tabs. I want to save the file by grabbing the customers name from the file (have this figured out), then after the script enters the file name according to the customers name I want to amend the name with what ever name is in the tab presently selected (being viewed). For example, I have 62 tabs, their names are below. I grab the customers name from the sheet and then grab the tab name and back to sheet to get address to make the file saved as * Folks, Gerry (X-Pave) 112233 Big Hill Rd 99002* I know how to get the name of all my tabs, this is the result, I have no idea how to grab the name from the tab to be sent to the save dialog box Here is my tab list...... expandcollapse popup[0]|Material| [1]|From Leads| [2]|Calculations| [3]|Formula| [4]|Overlay Drive| [5]|Saw Cut Overlay| [6]|X-Pave| [7]|Pave Gravel| [8]|New Construction| [9]|Overlay Parking Lot| [10]|Milling| [11]|Excavate 2C 2X| [12]|Speed Bumps| [13]|X-OVERLAY| [14]|Excavate - Gravel| [15]|Extension & Overlay| [16]|Overlay Pave Gravel| [17]|Gravel - New Construction| [18]|Excavate - New Construction| [19]|Surface Patch| [20]|Saw Cut Patches| [21]|Chip & Seal| [22]|Concrete Bid| [23]|Drain Blank| [24]|DS Ground| [25]|DS Asphalt| [26]|French Drain Asp| [27]|French Drain (2)| [28]|French Drain| [29]|Channel Ground| [30]|Channel Asphalt| [31]|Patch & Seal| [32]|Res Seal| [33]|Multi Areas| [34]|Com Seal Hot Pour| [35]|Com Seal No Cks| [36]|Com Seal| [37]|Com Seal 2| [38]|HOT POUR| [39]|Measured Areas| [40]|Dummy Bid 2| [41]|Companies| [42]|Bollards| [43]|Striping| [44]|Fax Cover| [45]|Concrete Cover| [46]|Res-Seal Coating| [47]|Com Seal-Coating| [48]|Repeat Cus| [49]|Cover Blank| [50]|Revised Bid Cover| [51]|Cover| [52]|Drainage Cover| [53]|New Res Cover| [54]|Tennis Court| [55]|GC Job| [56]|Blank| [57]|Referrals| [58]|Bid Number| [59]|WorkOrder| [60]|Blank Work Order| [61]|Manual| [62]|Cover Letter| Thanks in advance if anyone knows how Link to comment Share on other sites More sharing options...
water Posted September 27, 2016 Share Posted September 27, 2016 Why use the save dialog box, try function _Excel_BookSaveAs. 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...
qwiqshot Posted September 28, 2016 Author Share Posted September 28, 2016 That works too. I still cannot figure out how to grab the name from the currently viewed tab tho... Link to comment Share on other sites More sharing options...
water Posted September 28, 2016 Share Posted September 28, 2016 Can't test at the moment but I think it should be: $sName = $oWorkbook.ActiveSheet.Name 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...
qwiqshot Posted October 3, 2016 Author Share Posted October 3, 2016 One last question. I have it working exactly the way I want it to, but it takes a pretty long time to save the file (25 to 30 seconds). If manually save the file it takes very little time to save (2 to 3 seconds). can this be sped up any? ; Create application object and open an example workbook Local $sWorkbook = "c:\Excel\AsphaltEstimating.xlsm" Local $oExcel = _Excel_Open() $oWorkbook = _Excel_BookAttach($sWorkbook) ; Attach to Workbook $fName = ($oWorkbook.Worksheets(4).Range("J20").Value) ; Customers name $cAddress = ($oWorkbook.Worksheets(4).Range("I30").Value) ; customers address $sFilePath = "\\MYCLOUDEX2ULTRA\Bids\2017 Bids\Mark\"&($fName)&" "&"("&($oWorkbook.ActiveSheet.Name)&")"&($cAddress) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Fail", "Error Try Again" & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookSaveAs($oWorkbook, $sFilePath, $xlWorkbookDefault, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Fail!", "Error saving workbook to '" & $sFilePath & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Success!", "Workbook successfully saved as '" & $sFilePath & "'.") The resulting save file name is: Jones, Jesus (Pave Gravel) 777 Sky Ct Heavenly AB 77777 Jones, Jesus = $fName , Pave Gravel = ($oWorkbook.ActiveSheet.Name) , 777 Sky Ct Heavenly AB 77777 = $cAddress Link to comment Share on other sites More sharing options...
water Posted October 3, 2016 Share Posted October 3, 2016 I do not see a reason why it should take 30 seconds to save a workbook. Is this the whole script? 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