I have a C program that generates CSV files as output.
For example - I have 12 CSV files; one for each month. First column is Employee Name and Second column is their respective salaries. Assume there are 10 employees.
I want to format the 'salaries'column such that if a cell has a value over 10,000, the text should become green. Else it should remain blue. I have been able to do this using VBA for one file by adding a Command Button in the file and writing a small script.
However the issue is, every time I run my C code, it will generate a new set of CSVs; overwriting the existing ones. Besides, I want to apply such formatting to other CSV files I intend to generate.
I read that a .xla Add-In (which can exist on its own unlike embedded VBA macros in an Excel sheet) might be the solution.
I have 2 questions -
1. Is it possible to do with Add-Ins?
2. If yes, then I wanted to create a single batch file which would first generate the CSVs, and then run the Add-In on it. Is that possible too?
Thank You.
Related
I have to merge data from multiple Excel format files into one specific CSV file. I'm new in VBA, so I really appreciate any sample code.
Source data from the same Excel format file:
Cell B3: <UserName>
Cell B4: <Department>
Cell B5: <Mail address>
*These data are 1 user per 1 file in the same format. I'd like to append these data to the one specific existing CSV file in one click by using VBA macro in an each file.
Output CSV(existing CSV file):
<UserName>,<Department>,<Mailaddress>
User1,Sales,user1#domain.com
User2,HR,user2#domain.com
....
The first row is for the header info. I need to append data from the second row.
If you employ the Merge Tool in Excel, or use the Power Query, you should get what you want. In addition, try the AddIn below. This will do all kinds of copy/paste/merge tasks.
https://www.rondebruin.nl/win/addins/rdbmerge.htm
I have 1000 files in Excel format (Excel 2010) and each file contains 7 sheets with data.
This is an example for Excel sheet.
Is there a way to automatically convert the numbers that are stored as text to numbers, without affecting the actual text data? (maybe by VBA macros ? but I am a beginner in VBA code)
I can give you an algorithm, but I don't have time to write the entire code. I would write it in a seperate workbook, for repeatability. You can then either hardcode the 7 file names, or you can make an input for file name (the latter is a bit more flexible, if you need to use it for more files later).
Open a file
Loop all sheets
Loop all cells
If IsNumeric(Cell.Value) > Change format
You should be able to Google your way to the separate parts. Once you have some actual code, you can ask for more help on StackOverflow.
There are several threads here on SO which are concerned with filling and formatting an Excel sheet out of Powershell. The concepts for this are easy, but creating a report in this way can quickly become cumbersome -- particularly when a nice format is desired.
Therefore, I want to get rid of the whole formatting and instead base the report on an existing template, for example looking like
The fields A2, B2 and C2 then shall be filled through a Powershell script.
The straightforward way to accomplish this would be to create the Excel template once and save it somewhere as a file. Then let the script open the template, fill it with data, and save it somewhere else. Although this works, it is not nice as the powershell script is not self-contained: one always needs to handle two files, the script as well as the template.
Therefore, I'm seeking for a way to bundle together the script and the Excel template. My first idea for this is to export the Excel template as a series of formatting commands. (This is similar to the result of a macro, where one obtains VBA code, but a macro is not maintainable: if I want to add one column, I'd need to repeat the whole macro.)
Ideally, with this I would like to have the example sheet exported into Powershell like
$sheet.cells.item(1,1) = 'Name'
$sheet.cells.item(1,1).font.Name = 'Calibri'
$sheet.cells.item(1,1).font.bold = $True
... and so on ...
(As said, Powershell would be optimal, but I could also arrange with VBA, why I tagged it as well.)
Is it possible to create such an export?
Situation: every 2 weeks we need to download 3 Excel workbooks from a website, each time we need to open these 3 files and delete always the same rows, for example in the first downloaded Excel workbook we need to delete the first 4 rows, in the 2nd Excel workbook we need to delete the first 4 rows and then the 6th row, etc... What would be the best way to approach this? Could this eventually be done from within a DOS batch file or a VB script? Or is something more advanced required? Any help is most appreciated.
A VB script could do it. I'd suggest you create a new workbook, and record a macro into that workbook which does what you want. Then you could put a button onto your new workbook to run the macro. As long as all workbook filenames each time and rows to be delated are identical, that should work. Bear in mind, though, that I sometimes find that it's necessary to clean up the macros that excel records, in order to make them more robust.
We have are relatively simple Reporting Services report that our users commonly export to Excel. I've noticed that the files produced by the Excel export seem unusually large. If I open one of these files and just click save, without making any changes, the file size reduces to about half of it's previous size. Has anyone else run into this and is there a known workaround?
You've mentioned that the report is relatively simple, but this is important to check. The export to Excel will go to extraordinary lengths to try and maintain how your report looks.
If you have lots of different borders or colours (particularly if different formatting is determined by the data in your report) this will bloat the file.
Also check if many columns with very small and unusual sizes are created in the exported worksheet. The export does this to try and match alignment in Excel with the original report.
Try recreating your report as a basic table with no formatting or headers/footers and see if you can reproduce the problem. If Excel's behaviour is acceptable then add each piece of formatting back until it goes awry. Please let us know what you find.
I don't have an immediate solution, but a common problem in Excel is files bloating because one/some/all of the worksheets have saved all 64K rows instead of the ones being used. The fix in Excel is to select all the lower rows not being used, and delete them, then save the spreadsheet, close and reopen. Therefore, I'd pursue the angle of extra rows being saved in the export, and see if there is a way to keep this from happening.
What tool are you using when exporting to Excel?
I have also managed to reduce # of rows in my Excel worksheet by copying it to another worksheet, then deleting the original sheet.
You could also try copying only the data in your worksheet, and paste it into a new Excel Workbook (file).
I had the issue where the exported Excel files took and extremely long to open and they would stop responding every time you clicked on a cell.
Also, extra and merged columns would appear in exported excel files.
The fix was to make sure my header text boxes lined up with the beginning and end of columns in the data table just below it. Once both were aligned, there were no more extra columns in the exported excel spreadsheets and the performance was back to normal.
Here's the reference that helped me understand the issue:
http://www.codegur.press/12747988/issue-report-export-to-excel-in-rdlc-report
May be I am answering your question very late. Here's the solution for exporting to CSV.
You need to give the a name that you want to see as a column header for the field (not the column name) in the designer.
By default all the text headers are exported as a separate columns along with the table columns and make sure that you name the Design name in the properties with the name you want to see.
The other important thing to note about the option DataElementOutput which is set to Auto meaning it will be exported. You can change that if you don't want it to be exported.
The last but not least thing ... after you export the data looks messed up. You need select the whole first column and go to the Data tab - > convert text to column -> use the delimiter as comma and say Finish. That should solve your issue.