Convert XLS to CSV without login - excel

I have a PowerShell script to convert my XLS files to CSV every week. The script works well, but I have to run it manually as a login user to trigger an Excel instance in the background on my computer (as shown below).
$Excel_app = new-object -ComObject Excel.Application
I was wondering if anyone could give me some advice on how to automate this process, for example, if even my computer is logged out, the converting would still happen etc.
I am also open to rewrite the script in other languages, but I am not sure if others would also require a login user to open Excel etc.
Thanks in advance!

You can use Task Scheduler to run the task without a user logged in, but you may have to configure the DCOM permissions to get it to work non-interactively.
A better solution might be to use the ImportExcel PowerShell module, which is based on EPPlus so it doesn't need Excel at all. That should just work from Task Scheduler since there's no COM Objects at all, but there's a small chance of incompatibility if you're doing something particularly unusual with your Excel documents. It also has the advantage of not requiring Excel to be installed.

Related

Add page break in excel with the module ImportExcel (Powershell)

I'm actually trying to generate a large report with multiple groups in powershell. I want to seperate each groups of data in a single page, but I'm struggling to find the method to add a horizontal page break with the ImportExcel module.
I'm starting to wonder if it is doable. I know that it is possible with the excel interlop com object, but the script with be run with an elevated user right on a server, so we do not want to install excel on to.
So far I've look at the module methods and I did not find anything. It seems like we have access to the document/sheets xml so if someone knows how to do it in xml, it could also do the trick.
I'll post my answer since I found it. The module ImportExcel is based on the EPPLUS library for c#.
I've take a look in the library and there is a way to add a break line fairy easly, but does not show in powershell.
$Sheet.Row($line).PageBreak = $true
It's that simple. There is just not obvious documentation and the intellisense was not finding it too.

Running SAS programs from excel

I have a few SAS programs that I need to run from excel. The programs pull tables from SQL, perfom some calculations and give an output table that I would like to present in Excel. So I figured that it would be great to run everything in excel.
There are a few parameters in the code that need to be changed before running, so the best idea I had is to put the SAS scripts in cells on an excel sheet and change the variables with VBA.
My question is, is this achievable? Can I connect to SAS and do everything from excel?
I'm fairly good with VBA, starting to learn SAS, but I don't really know how to connect the two. Thank you for your help!
Yes it is possible , i did this in my work a week ago , SAS have an documentation here?
The link below can help you.
http://documentation.sas.com/api/docsets/itechwcdg/9.4/content/itechwcdg.pdf?locale=en
You can use ADODB to connect to , see here for the strings
https://www.connectionstrings.com/sas/
Your options are:
1) use VBA to connect to IOM, create a workspace, run your program.
This requires quite a bit of VBA, as well as the SAS Addin for MSO, and various components.
2) Run a Stored Process (STP) via point and click using the MSO addin
Again, this requires a desktop SAS Addin deployment, and isn't scriptable with VBA
3) Run a Stored Process as a web query
This is an excellent option - you don't need any special desktop installation, you can easily add (url) parameters, you can use it with / without VBA, and your output will render easily into your worksheet so long as you stream tab delimited data via the _webout fileref (without %stpxxx macros). It will also work with all versions of excel and SAS.
This approach is described here: https://www.rawsas.com/sas-as-a-service-an-easy-way-to-get-sas-into-excel-power-bi-and-000s-of-other-tools-languages/

close Excel from PowerBuilder

Working with PowerBuilder, I'm using an OLE object to make some changes in an Excel document, but when I disconnect the object, the Task Manager shown that it's still running. Also, if I open another Excel document, I can then open the Excel document that I made changes in.
I've tried just about everything I have seen on here, but most are using C# or something other than PB. The code that I've see and tried, doesn't run in PB.
Any ideas?
ole_excel = create oleobject
ole_excel.ConnectToNewObject("excel.application")
ole_excel.application.quit()
ole_excel.DisconnectObject()
In Task manager, I see the following:
EXCEL.EXE *32
Thanks,
Queue
Sometimes the process remained for whatever reason, I code a
Garbagecollect()
and the process vanishes.
Take care.
Georg

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.

Check if Excel workbook is open using VBScript

I have a vbs script which writes to an Excel spreadsheet. To be able to save the spreadsheet I need to ensure that it is not already open.
Can someone suggest the best way to do this?
Some research:
I tried to create a Word Tasks objects to show me all running processes, but on Windows 7 it only tells me whether Excel is running or not.
Creating an Excel.Application object does not give me access to all running instances of Excel.
I thought about opening the spreadsheet for writing but the only way I can think of doing this is with the File System Object OpenTextFile method which does not seem to be the correct approach as the Excel file is a binary.
Any other ideas?
Since the Excel.Application object doesn't give you access to all instances of Excel, what about using a simple error trap? ie. if it is unable to save the file, throw a warning message, save as another file name, etc.

Resources