Scenario: 2 Excel (.xlsx)sheets: INPUT, OUTPUT in same workbook. Calc set to manual.
User inputs numbers (e.g.,sales forecast). Wants to push one key (F9, click Run or a button on the INPUT sheet). Unknown to user a python script is called, executes (say with xlwings or openpyxl) calculates the expected sales for the year and sticks in somewhere in the OUTPUT sheet.
User then prints it out and takes it to his boss for a VIBM (Very Important Business Meeting) while the rest of the folks actually work.
Trivial with VBA involved, but many firms (especially banks) do not allow Excel sheets to run with macros allowed. Someone read that it opens their analyses & systems to hacking.
Is this possible? Any other ways to do it? I could just have a command window open along side, but that gets scary when you consider the users.
Thanks,
C
Related
Hello stack overflow world!
I'm a self-thought programing enthusiast, with not much experience.
I have made a python script and turned it into .exe that more or less does the following:
Based on user input, opens some webpages and saves them as HTML files,
Runs an excel macro that refreshes power queries connected to those saved files,
Runs a macro in a word document linked to that excel, that smooths out the text and saves output as a word document containing sales a purches agreemnent for a real estate, filled with information scraped online.
I was trying to host this whole operation to a sever, to be able to run it from anywhere. Any ideas how I might be able to do it? I ran out of ides what to type in google in order to procdeed with my little project.
I have looked up Common Gateway Interface (CGI) but I'm not sure if this is the right approach.
I have an excel add-in (morningstar) that allows me to request and download data by entering a function with some parameters in cell A1. I have a thousand values of parameters that I need to get the data for so I would want to automate this process. I can (sort of) do that with VBA but it takes forever, and crashes many times. I would like to do this in Python. The logic which I am doing in VBA is as follows:
Open the xlsx file (workbook)
Refresh Excel so to make sure the Add-in is loaded and data is downloaded
Loop through sheets and save as csv files
I tried opening the excel file with python using the subprocess package. But I cannot make it until the data is downloaded. I attached 2 photos of the download process: (i)when the function in cell A1 is executed, the cell display "Processing..." . It would take a few seconds to a few minutes depending on the size of the data. when done, the data looks like in the second photo.
So my questions are:
How to ask python to start excel and load the add-in?
Execute the fuction in cell A1, or at least refresh excel to make sure the function runs.
Instead of asking python to wait for an exact time, how do I ask python to check if the data is downloaded?
Ideally, (I think) doing this without opening excel would save a lot of time, but not a major issue.
I am using python package 'jira' for establishing connection with the jira. I basically use the information from excel file and create tickets automatically in JIRA based on the excel information. Sometime there might be changes in the excel information for the same ticket in which case I need to run the code manually. So I would like to know if it is possible to do this automatically whenever there is a change in the excel file.
I assume you are only interested in filing new tickets. i.e. adding new rows in excel sheet.
Two options:
Run your code in a forever loop with sleep.
Have your code run by a cron.
Now, you can maintain the hash(md5 or sha256) of your file, and write the hash in some file on host machine if you are not using a database.
Your code has to read from this file, and calculate fresh hash of that excel file. If they are not same, means something has changed in your file.
Now, you also need to maintain till what row you have created the jira tickets. You can write this information also in some file.
I have a data base of hundreds of submitted forms, every submitted form contains various modules with VBA code in them to process the data.
Each form file name starts with same unique prefix.
All of the forms are saved in our main global directory of documents.
Data from every form is logged into a log file.
VBA code within each forms allow me to change information in the form and send the updated information into the log.
Now because of the office 2019 being introduced, vb scripts in every form made in 2016 version is not working and I have to force change the code in every single form to make it compatible with 2019.
This mass change is not only required due to office version change but also required because I need to update log file with additional information contained within the forms cells which old VBA code does not process.
There are 4 VBA modules in every form file and scripts in every modules needs to be replaced with the new code.
Really don't know where to start, any ideas are much appreciated.
I have no idea what to try.
Expected result is that I have updated/new code for 4 macro modules currently exist in 100's of files which needs to be replaced over the old codes.. of excel files starting with a common unique prefix.
You can use VBA to modify VBA projects. For this, the "Trust access to the VBA project object model" checkbox must be ticked in the Trust Center/Macro Settings.
After that, open the VBA editor. Set a reference to "Microsoft Visual Basic for Applications Extensibility 5.3" (possibly the version is different for you, I don't know).
Now a couple of additional classes become available under the VBIDE library and those can be used to manipulate VBA projects programmatically. (I'm using this feature to export VBA modules for source control.)
There is no easy way to modify the text of the module, but you can try exporting, deleting and re-importing them to see if that already is enough:
Sub Test()
Dim vbcs As VBIDE.VBComponents
Dim vbc As VBIDE.VBComponent
Dim filename As String
Set vbcs = ActiveWorkbook.VBProject.VBComponents
For Each vbc In vbcs
Debug.Print vbc.name
If vbc.name = "The ones you want" Then
filename = GetFilenameFromModule(vbc)
vbc.Export filename
' you could modify the file contents now if needed
vbcs.Remove vbc
vbcs.Import filename
End If
Next vbc
End Sub
Private Function GetFilenameFromModule(vbc As VBIDE.VBComponent) As String
Select Case vbc.Type
Case vbext_ct_ClassModule, vbext_ct_Document:
GetFilenameFromModule = vbc.name & ".cls"
Case vbext_ct_MSForm:
GetFilenameFromModule = vbc.name & ".frm"
Case vbext_ct_StdModule:
GetFilenameFromModule = vbc.name & ".bas"
End Select
End Function
Be sure to check out the properties of the various objects in the debugger or object browser (F2), just to see what's available. I'm not sure how well documented all of that is, but it's versatile and stable.
To work with files in VBA easily, you can set a reference to the "Microsoft Scripting Runtime" library and use the FileSystemObject.
I have a peculiar situation lets do a background.
Background:
We have a script that was developed in house for testing enterprise servers. The script is written in Bash. The magic of the script is the dmidecode command. The script runs on Linux Mint and is deployed via PXE. The output of the script contains hardware information about the processor, memory, system board and chassis part numbers, etc. This information is always changing depending on the device the image is booted on. All this data is then grepped into a readable format that then manually gets added into an Excel spreadsheet. The Excel sheet is broken up like this Row 1: A1(Asset Number),B1(Qty."always 1"),C1(Manufacturer),D1(Model),E1(Part Number),F1(Serial Number), G1(RAM (Mb)),H1(# of CPUs),L1(CPU Speed(GHZ))
Example Data
Column Names:
Column Data:
Row 2: 6112, 1, HP, Proliant DL580 G2, 325134-001, USE247ML97, 1024, 2, 2.8
So each row represents an individual server, the columns contain the data that comes from our previously mentioned bash script.
Goal:
OK, so my goal is to have the output of the bash script automatically be appended to an existing Worksheet that is stored on a local CIFS File Server. Since script is initiated on Linux, Powershell is not a viable option.
I think Openpyxl can do the job but I have no idea the best practice to approach this. I know that I will not be able to modify an existing workbook. Given that, I was thinking about loading an existing document in memory and overwriting with the same file name. Also, all the tutorials I see for Openpyxl seem to have static data, I do not have this luxury. Is this even possible or just a subtle daydream?
For an excel sheet i would use XLSX parser to read the spreadsheet and XLSX writer to make a whole new spreadsheet based on what you have read. However, for what you appear to be doing. Would it not be easier to put STDIO into a CSV?
e.g,
echo $VAR , $VARB , $VARC >> ~/servers.csv