Search directory for single file and add file to zip - excel

I'm wondering if this is possible and the best way to accomplish it if it is.
Scenario: We have multiple sites that create a "dated subdirectory" each day at a certain time. The dated subs contain information for that day of business.
I need to pull a single DBF file out of the dated sub each day and either export the data to an ever-expanding Excel file, that contains information from the single DBF file from EACH day so it looks like:
Day 1's information
.
.
.
Day 2's information
.
.
.
Day 3's information
OR
Add a copy of the DBF file from each dated sub to a ZIP file that is done daily.
The name of the DBF file never changes, and can't be deleted.
I'm thinking it could be done with a forfiles command, but am curious if it could be done more efficiently. The file that searches, pulls, and zips would be run as a task nightly.
As an add-on, could it be pushed to a Google Drive for safe storage?
Sorry if this is rambling. This is something I'd love to try to do, but not sure where to start exactly.
-Dated sub created nightly, single file from that directory needs to be pulled or read and transferred either to an Excel file or copied to a ZIP with a way to seperate each file, maybe a directory with date as name?
Also, if able, it needs to start with a particular date, like 6/1/2014 but no further back.
Thanks in advance for any help.

Can you merge data from a DBF file to an Excel file? Not really with pure batch, but you can use JScript or VB Script. You'll need the MS ACE OLEDB 12.0 driver. Then you can use a connection string for DBF and another for XLSX. (If you're using XLS or CSV, you could get by with the MS Jet driver, running the WOW64 version of cscript.) Once connected, just use SQL queries. SELECT * FROM dbffile, and as you're looping through the recordset, INSERT INTO xlsxfile.
Can you append a DBF file to a zip file? Probably. I'm guessing 7za.exe a will append to the archive if the archive already exists. Try it and see. Or were you wanting to script the zip functionality without 3rd party software?
Can it be copied to a Google Drive? Well, yeah, the Google Drive software watches and mirrors a folder on your hard drive. So chances are, copying the file to %userprofile%\Google Drive\ will do what you want without any conscious effort.
Try posting another question. But rather than rambling again, find one specific problem where you're getting stuck, and explain what you've tried without success.

Related

Shortcut with environment variable

I'm at work, with a folder in which we create a daily excel sheet to manage our clients. For the sake of understanding let's imagine this files is in a folder called OCTOBER and they are named MD01, MD02, MD03... based on the day we are.
I was trying to setup a shortcut on my desktop that will call the correct file every time so I don't have to go trough the file structure to access it. Something like this:
"....\OCTOBER\MD%DAY%.xls"
But the moment I try to setup the path this way I get an error say this is not a valid path. Well, either I am missing something here or what? Can't this be done?
A typical method is to create a link to a master file in the folder (say master.xlsm) The master spreadsheet would automatically:
determine the date
determine the appropriate file to open
open the file (say MD10.xls)
close itself
Alternatively you could create a little vbscript or powershell script or .bat file to do the same thing.

Batch file for inserting macro's

I am trying to create a batch file as icon on desktop, that would open a specific excel file, create a macro in it and copy code from a specific txt file into it.
The reason i need this, is that the file is located on a server and the ending .xlm cannot be cahanged (should not) so i cannot save it as a macro enabled file (to store a macro in it )
Could annyone with better understanding please explain to me how to create the said code ?
Thanks in advance!
In theory it's possible by using the VBE object (https://msdn.microsoft.com/en-us/library/aa443984%28v=vs.60%29.aspx). But that's not activated by default so you can not ensure that each user is able to do that.
Better find other solutions for that problem. Can you upload .XLSB for example? Or do you have another kind of server available - for example a database server - you can use for storing the file? We use this method here for deploying our updates on AddIns and report templates for example.

How to automate SAS EG 4.1 program daily and put the output in Excel and run VBA and print PDF?

I am totally new to automation, but trying hard to find answers online everywhere for 1 week. I could not able to do what I wanted to do. I have a SAS enterprise guide 4.1 old version and program runs on a SAS server. I have a SAS report due every day at 9:30 AM. I have the code that is already setup and working fine. I need to automate this program to run at 8:00 AM every day, then move the output to a specific excel file in sheet 1 at specific cell range, then invoke the VBA macro button (UPDATE) placed in the sheet 2 and then print out two worksheets in the same file as a single PDF file to somewhere in my computer. I will have to upload this into a CMS. I wanted to automate until the step before the last step, creating the final PDF report on a daily basis.
When I thought about all these I was stunned. I actually created a batch file in notepad and made SAS to open the file at specific time using Task Scheduler in Windows XP control panel. However, SAS did not run the program.
Here is the batch file code:
Start/w C:\PROGRA~1\SAS\ENTERP~1\SEGuide.exe –sysin "Z:\ccccc\vvvvv\Report.egp"
If anyone could please help me, I would like to know how do I make the SAS to run the program in the SAS server and also where do I provide the user name and password for the SAS server authentication. Can anyone please give me an example how to write this code in my batch file. Also, how to export the output into the specific excel file in SHEET 1 and then run the VBA macro. Then how to print out PDF files of two worksheets as a single file and place the final PDF file in the C:\Report folder.
I am sorry it is too much information, but if someone could help me figure out, I would really appreciate all your help!
Park
Enterprise Guide automation is a bigger issue than can be covered in a StackOverflow answer in detail. In general, EG exposes itself to automation through a DLL (SASEGScripting.dll), which you can then automate using VBScript, Powershell, or .NET (C# etc.). You need to read the documentation for the API or read a tutorial.
Chris Hemedinger has several good explanations of how to go about doing this; for example, see this article, or browse his blog articles.

Cannot connect csv to Excel thru ODBC

HI;
I cannot connect a CSV file to a SpreadSheet when the file is open. Currently a have a csv log file that is being constantly updated. I was able to connect it a an Excel SpreadSheet by normal import from external source with refresh every hour. However, its a big file so I needed to produce the reports using EXCEL SQL. It will not allow me to connect to the file while it is open. It says that the MS Jet database engine cannot open the file'unknown'. It is already opened exclusively by another user or i need permission to view its data. If granting permission is he problem , where do I grant myself permission. On a standard Impor, I have no problems reading the file while it is open, but otherwise, get this message and cannot proce3ed. Any help would be appreciated. If I close the update program, I am able to run the queries, but not if the update is running.
Using MSO 2007 W7 x64
It will not allow me to connect to the file while it is open.
That's right, it won't - there is no way to change this.
You must find another way to solve your problem.
How big is the file? You may be able to make a copy to a temporary filename, and connect Excel to that instead.
It sounds like you are accessing a logfile. LogParser can read CSV. In any case LogParser has an excellent SQL-like syntax and can read CSV files much more quickly and reliably than ODBC. It is also programmable from Excel VBA (or script). Perhaps you can use LogParser to extract the values of interest and then load those into your Excel table instead.
I suspect your best solution will be to use the LogParser MSUtil.LogQuery object from Excel VBA, to extract the values of interest into your spreadsheet. Since I don't know what you are actually doing this is just a guess!
I cannot recommend LogParser highly enough - it is a wonderful tool, and can read just about every standard type of logfile, CSV, TSV, W3C, as well as plain text files and the windows NT event logs:
LogParser 2.2 Download: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en

Excel Sheet Project References

I am programatically opening excel workbooks under a folder tree to check for some project references using the following code -
workbook = app.Workbooks.Open(fileName,false,true,Missing,Missing,.....);
foreach(Reference r in workbook.VBProject.References)
{
//check for a specific reference here
}
This works fine but my folder structure is very deep and I have over 20,000 spreadsheets stored in them. Sometimes depending on the size of the excel file, the call to Workbooks.Open() takes a long time (over 5 minutes per call on some files). Is there a faster more efficient way to do this?
Thanks for the help
It seems like whenever you have to hit the Excel object model, you're going to take a performance hit. I agree with the previous poster, that if you want to speed up performance, you'll need to read the Excel files directly.
As a side note, since Excel 2007 files (*.xlsm, *.xltm) are essentially *.zip files, you would need to find and access the vbaProject.bin file directly. A quick look points to the path as (I changed the extension so I could browse the file):
..\Book1.zip\xl\vbaProject.bin
Obviously you could dig through that bin file manually and find particular references (as suggested by the previous poster), but if you're looking to loop through all of the references in a project, you'll need to use the API calls IStream/IStorage. There's a great article about reverse engineering the Office BIN files here: http://www.codeproject.com/KB/cs/office2007bin.aspx. To access references in vbaProject.bin, look for the section titled "Reading or updating vbaProject.bin parts". There is also a sample C# code project that demonstrates how to read an OLE container. I just took a peak at the code sample, so I can't attest to it's effectiveness, but it certainly seems in order.
Hope that helps!
I don't think you can increase the Workbooks.Open performance. However if your main intention is just to check if a particular reference is used by the Spreadsheet or not, then consider opening the Excel file in binary mode and searching for the dll string.(The path of the dll providing the functionality, which can be seen in the Location part of the References Window).
This would be very crude way, but if the Workbook.Open performance is really a bottleneck then you can definitely give it a try.

Resources