ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   excel in the foreground (https://www.excelbanter.com/excel-programming/332203-excel-foreground.html)

Jono2000

excel in the foreground
 
i need to call excel from outlook to open an attachment and saveas in a
different format (csv as it happens).

i'd much prefer it happened in the background. ie the email is received in
outlook, and the functions are carried out without it taking over the pc.

whats the easiest way to reference Excel and do this, or do i have to accept
excel coming to the front and activating when my email is received?


K Dales[_2_]

excel in the foreground
 
You can keep the entire operation in Excel hidden from the user. In fact,
when you create an automated Excel session it is by default invisible unless
you make it visible. Here is the basic outline for running the Excel
session, assuming you are using VBA from Outlook. Note first that you need
to go to the VBA editor and add a reference to the Microsoft Excel Object
Model:

Dim xlApp as Excel.Application
Dim xlBook as Excel.Workbook

Set xlApp = New Excel.Application ' this starts up Excel in a hidden session
' xlApp will remain invisible unless you do xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add ' Now you have created a workbook to use
' OR
Set xlBook = xlApp.Workbooks.Open (FilePath) ' to open an existing file
' Do whatever processing you need to do here...
xlBook.SaveAs FileName:="NewFilePath.csv" FileFormat:=xlCSV ' Saves as csv
file
xlBook.Close ' Closes the workbook
xlApp.Quit ' Exits Excel

Set xlBook = Nothing
Set xlApp = Nothing ' Cleans up object variables



--
- K Dales


"Jono2000" wrote:

i need to call excel from outlook to open an attachment and saveas in a
different format (csv as it happens).

i'd much prefer it happened in the background. ie the email is received in
outlook, and the functions are carried out without it taking over the pc.

whats the easiest way to reference Excel and do this, or do i have to accept
excel coming to the front and activating when my email is received?



All times are GMT +1. The time now is 11:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com