How do I automate searching information of a list and pasting it to a document - automation

I'm new to programing. I decided to learn how to automate menial task for my school research project. I have a large list of animals that I need to collect information on and record it on a table; like a spreadsheet. I want to make a program that scans through the list, then searches for the animal and downloads a picture of that animal then searches of other information on the animal (like body length) and pastes it to the spreadsheet. Truthfuly I have no idea where to start, what language would be best for this or whether its possible so any help would be appreciated.
I know this isnt much but this is the test code I wrote for pasting the info into the spreadsheet in python
import openpyxl wb = openpyxl.load_workbook('spreadsheet.xlsx') sheet = wb.active sheet['A1'] = 'Hello World!' sheet['A2'] = 'Good Bye World' wb.save('spreadsheet.xlsx')
overrall I'm pretty lost so any help or direction would be great

Related

How to select current row in SAP GUI Grid View with VBA Macro?

I am trying to automate a repetitive task in the SAP GUI. I need to search for an order number, select the row that the order number is in and then click a button to complete the task. I have recorded a macro which gives me:
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarButton "&FIND"
session.findById("wnd[1]/usr/txtGS_SEARCH-VALUE").text = "4521305207"
session.findById("wnd[1]/usr/txtGS_SEARCH-VALUE").caretPosition = 10
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/tbar[0]/btn[12]").press
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").currentCellColumn = ""
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectedRows = "2894"
session.findById("wnd[0]/tbar[1]/btn[14]").press
session.findById("wnd[1]/usr/chk[1,6]").selected = true
The line:
session.findById("wnd[1]/usr/txtGS_SEARCH-VALUE").text = "4521305207"
Corresponds to the order I want to search, but if I change this value it still tries to process the same order that the macro was recorded on, I'm assuming because of the line:
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectedRows = "2894"
Does anyone know how I would go about finding the number of the row which corresponds to the outcome of the SEARCH-VALUE and then using that as the .selectedRows = ""?
First of all I'd really recommend you add a reference to the native SAP library. Go to your VBA Editor, click Tools, then References, then Browse, and find this file: "C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx". Add it, and now you'll have types and libraries and coding for SAP will be a lot easier, safer, and slightly faster (Variant types in VBA impose a tiny overhead that in this case is totally unnecessary). Get familiar with this new library if you are going to do any SAP scripting more than once.
Second, about this problem, what you have is a shell, of type GuiShell, which inherits from GuiGridView. GuiGridView looks like a table, a classic Excel-like set of rows and columns. In your transaction, is showing you a big list of orders, in which you go click the "Find" button, put the order you're looking for, and then close the Search Window. Back to your (Grid)Shell, this cell has been selected (Grid has properties SelectedCells, SelectedRows, SelectedColumns that get all set when you go find something), but then you go and modify the value of SelectedRows to a specific one.
So yeah, upon find, a cell has been selected, so all you need is to query its row and then assign it where you need:
Dim numrRow As Long
numrRow = session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").CurrentCellRow
session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").SelectedRows = numrRow
where "thisShell" is however you do to find a reference to the Shell (session.findByID("blabla") for example, but I'd advise to reduce all the findByID's, they're very slow and type-unsafe).
If you need help about this SAP libraries, feel free to maybe make some new post and ping me on the comments about it.

VBA Import/Copy Specifc Worksheet witout Opening Workbook

thanks in advance.
I've spent nearly two days routing around but can't quite find/workout what I need.
I need to get an entire specific worksheet from a closed workbook without opening (even in the background).
Further info:
1) My source file has several sheets that I don't want/need. I only need one and it seems sloppy to copy all and trim the data down (plus it means moving large amounts of data unnecessarily).
2) The end goal of this is to save the sheet as a third, seperate, workbook. So if you know a way that helps this that doubles your awesomeness.
3)Targeting individual cells is not a viable solution, there's too much and the code would be huge/akward/cumbersome.
4) I've found a way to import all sheets into my operating/active workbook but cant figure out how to make it target a specific sheet (I'm missing osmehting simple I'm sure).
Test code snippet:
Dim Importsheet As Worksheet
Sheets.Add Type:= _
"C:\Users\haa\Documents\Personal\My Hours E2V-mk3.xlsm\"
Seems simple enough right?
5) Finally, I've seen some potential solution routes that uses "executeexcel4macro" (something I've never even seen before) but so far it only seems to target cell ranges not sheets.
That's all the key info. I really have dug around (and would have liked to crack this myself). Reminder that I'm looking for a way to do this without copying individual cells or opening the source sheet.
Thanks again campers!
4) I've found a way to import all sheets into my operating/active workbook but cant figure out how to make it target a specific sheet (I'm missing osmehting simple I'm sure). Test code snippet
Import all the sheets, then delete all but the one you want to keep.

Modify range of Hyperlinks in Excel

So, I have a spreadsheet that I have sent out to several of our staff asking to update certain fields/columns. I have a Document Link field (Column G) which links them a folder in our F: Drive which they can use to help populate the necessary fields.
The spreadsheets which I want them to complete are also in this F:Drive. However, I noticed each of the document links no longer work, and when I check the link under Edit Hyperlink, I notice instead of the desired "*F:\Procurement..." I have my home drive "+\NSH-HDRIVES1..." as the header,
F:\Procurement\Contracts\Alco...xxx...
\NSH-HDRIVES1\Contracts\Alco...xxx...
I have hundreds of these lines with document links that need "\NSH-HDRIVES1" replaced with "F:".
Is there some kind of VBA Macro that will let me do this? I have little experience and time to learn VBA Macros at this point so any help would be greatly appreciated. Note each link is different and goes to a different folder within our F:Drive, all I need is to change the prefix.
Thanks and sorry for any duplication.
The following code may help, but it is set up to only work on the ActiveSheet. If your hyperlinks are in multiple workbooks and multiple worksheets you will need to loop through them all.
For Each h In ActiveSheet.Hyperlinks
h.Address = Replace(h.Address, "\NSH-HDRIVES1\", "F:\Procurement\")
h.TextToDisplay = Replace(h.TextToDisplay, "\NSH-HDRIVES1\", "F:\Procurement\")
Next

I want to copy the format of one Spreadsheet in google docs do another spreadsheet. Is this possible?

I'm working on a feedback system for my math students and have a matrix that shows what points they have gotten on a test.
I have several sheets in this document with one sheet per student. I have also made one spreadsheet per student that i have put in a shared folder on Google Drive where the students only have viewing rights.
What I want to do is copy the entire sheet from my master document to the student's spreadsheet. This is all fine if I use the import range function however with that the formatting doesn't follow.
Is it possible to use a script with the commands getBackgroundColor() and setBackgroundColor() to transfer the backgroundcolors from the master sheet to the students sheet?
I started with something like this:
function getColor() {
var sheet = SpreadsheetApp.openById("0ApOkn5XcO_GDdFd4SDBaaFpLSEUxXy1vN2pnNHBpYnc");
var ss=sheet.getSheetByName("Student1");
var r=ss.getRange("A1:R34");
var color = ss.getBackgroundColors();
That's about as far as I get. Anyone have ideas?

Transferrring Data from an Excel Spreadsheet to Visual Basic

Hi there im having issues trying to transfer data from an excel spreadsheet to visual basic in the form of an array,any one know any reasonable means of doing so.I have searched online extensively but still cannot find a good tutorial on how to code it.
Simple step by step instructions with explanations would be appreciated as while im familiar with some parts of object orientated programming,I have never transferred data in this way.
Eventually I want to transfer this data onto an object orientated table with a few added buttons and functions thrown in
Cheers for any help guys
The easiest way would be to customise the following code:
examplerange = workbooks("Workbook 1").worksheets("Sheet 1").range("A1:B17")
where Workbook 1 is the name of the workbook that you are using (minus the extension, e.g. '.xlsx'), Sheet 1 is the name of the worksheet the range is located and A1:B17 is the range in which you wish to import.
This creates a Variant array-which is inefficient-however this is an easy way to import data into VBA and acceptable if you are not working with large sets of data.
Once you're more familiar, you'll be able to separate the elements in the code above and iterate through dynamic ranges as well as being able to import string / integer / boolean arrays to reduce memory usage.
Hope this is what you're looking for.