How to attach pdf embedded in excel in outlook email with vba - excel

I have created an embedded pdf with the insert> object > create from file> browse > display as icon function in excel.
I would like to then use the embedded pdf as an attachment for my outlook email using vba code. I have tried to use the .Attachment.Add code but it seems to fail to detech an embedded object.
Could anyone advise a correct code? Thanks!

Get the file from the source?
I don't understand why you would need to embed the.PDF object in the workbook, if you're going to be emailing it separately anyhow...
Regardless, you could just grab the actual/original .PDF to attach a copy to the email, directly from the same location from where it was embedded. (If it's not there, what happened to it?)
Another option:
As soon as you right-click the embedded object, Excel 2016 "gets ready" for you to open it by extracting it to your local temp folder. (I'm unsure whether this applies to previous versions.)
Therefore, you could programmatically right-click the embedded icon, and then check the temp folder located at the path that you'll find stored in Environ("temp"). One or more copies of your file will be located there (and it should be the 'newest' PDF).
Yet another option:
Excel's XLSM file is simply a compressed ZIP file, if you change the extension. You could programmatically make a copy of the file, changing it's extension to .ZIP.
Embedded object are stored as .BIN files within the ZIP file in the xl\embeddings\ folder. It would have to be extracted and then renamed back to a PDF. Note that this method is a little flakey and won't work with all PDF's.
More Information:
VBA Express : Save embedded PDF file as a separate PDf file
How-to-Geek : How to Extract Images, Text, and Embedded Files from Office Documents

Related

warning message in excel file

I code an asp file to response an excel file using Excel.Application object. I change the content type below.
Response.ContentType = "application/vnd.ms-excel"
When user downloads this file and open it, he get the following message.
The file format and extension of 'test.xls' don't match. The file
could be corrupted or unsafe. Unless you trust its source, don't open
it. Do you want to open it anyway?
I don't want to give this message to use. How can I remove this message from excel file.
This is due to a feature in MS Excel called Extension Hardening. There are 2 ways to fix this problem
You need to generate proper XLS files that are truly excel files, not HTML Tables saved with XLS extension
Each of the client machines need a registry tweak as explained here

Opening xlsx file created with SpreadSheetGear

I have created a simple Excel file using SpreadSheetGear. If I save it as an xls file
workbook.SaveAs("file.xls", SpreadsheetGear.FileFormat.Excel8);
and attach it to an email, I can open it on my phone (tested both with iPhone and Android).
If I save it as an xlsx file
workbook.SaveAs("file.xlsx", SpreadsheetGear.FileFormat.OpenXMLWorkbook);
and attach it to an email, I CANNOT open it on my phone.
If I open the xlsx file attachment on my computer and save it with no changes and attach it to an email, I now can open it on my phone.
Apparently Excel saves the file differently than SSG. The file size of the xlsx file attachment is 9 KB. When I open it on my computer and save it, the new file size is 24 KB.
Some of my users prefer the xlsx format. Is there anything I can do with to make the SSG generated file attachment open like an Excel generated file attachement?
iOS depends on certain attributes being present in the worksheet data of the Open XML file format to properly parse these files. SpreadsheetGear does not write these attributes out because they are listed as optional in the Open XML file format specification and, also, omitting them reduces file size, as you have noted. Excel, for whatever reason, always writes out these optional attributes and other third-party components often times rely on their presence to function correctly. SpreadsheetGear V5 added a workaround to write out these attributes by enabling a certain "Experimental" option. This option was added because the OLE DB provider also exhibits this errant behavior. You might try something like the following and see if this helps in getting SpreadsheetGear to better work with your viewer:
IWorkbookSet workbookSet = Factory.GetWorkbookSet();
workbookSet.Experimental = "OleDbOpenXmlWorkaround";
IWorkbook workbook = workbookSet.Workbooks.Open(#"C:\temp\BadWorkbook.xlsx");
workbook.SaveAs(#"C:\temp\GoodWorkbook.xlsx", FileFormat.OpenXMLWorkbook);
Please see the SpreadsheetGear.IWorkbookSet.Experimental property for more information on this feature.
From what I can tell, iOS/Andriod/etc often also depend on other certain optional features available in the file formats that SpreadsheetGear either doesn't support or write out by default. For instance, iOS depends on a "data cache" stored within charts to display chart series data points and SpreadsheetGear's support for writing out this data cache is limited. This can result in charts not displaying as expected in iOS, Android, etc.

Importing An Excel File From An Embedded File In A View

I'm currently attempting to take an embedded file (an excel xlsx file in this case) from a document inside a view and import the data into a DataArray for editing. The way the system I am working on is set-up, I will not a local drive to ExtractFile() onto - so I was curious if there is a way to basically take the xlsx file directly from the document that has it embedded in it and 'open' it in my agent to then extract the data from.
Thanks!
-Mike

Make Infragistics UltraGrid Document Exporter launch file

We have an existing application that allows exporting of an Infragistics data grid to either Excel or PDF format. Currently, when the user clicks on the Export button, it asks them where to save the file and then it exports it and saves it. Then, to launch it, they go to where they saved it and then it launches.
The user wants the application to instead launch the grid into either Adobe Acrobat or Excel and THEN that is where the user can opt to save the file. They don't want it to ask where you wish to save it before it exports, like it currently is doing now.
Is this possible with the Infragistics Document Exporter? I couldn't find any information on this from the Infragistics web site.
I'm thinking, instead of giving it a filename, I could instead use a stream maybe to the console or something like that and let the OS give the user the option to launch it?
Is there an example somewhere of this being done? I see there is an overload in the Export member function that allows you to pass in a stream.
Thanks!.
The Infragistics excel engine and documents engine will need to write to a file to be able to have the file opened in Excel or Adobe Acrobat so you will still need to save a file before they can open it.
For the requirement to open the file, you could use System.Diagnostics.Process.Start method and if there is a program associated with the file type you can pass the file that you just saved.
As there is a dependency on the file system to open the file in Excel or Adobe Acrobat you will not be able to achieve your goal of not requiring the file be saved first. While it may be an option to save the file in a temporary location and then open that file it also has an issue that if the user were to click save in excel it would still save in the temporary location so they would need to know to use Save As to save in a different location.

Possible to create thumbnails of MS Office files?

Have anybody ever tried to create thumbnails/previews of MS Office files? I do not mean extract saved preview images inside the file, but actually create them. Would this even be doable?
Could one print to an image/pdf directly in code?
In a general VB/C# application, add the MSword/MSexcel component and call the component to open the file you want. Then call one of the print functions with the parameters corresponding to first page etc.
This link shows how to open a .xls from C#

Resources