Fonts look different when inserting Excel table in a Word document - excel

I am trying to use a VBA macro (for Office 2003) to do the following:
In Excel, the user will select a range of cells
In Word the user will call the macro (via a button or shortcut) to insert the selected Excel range as an embedded object
The code is not the problem so far, my problems are:
Given that the user is working in a Word document, most likely will use the same fonts in Excel
When Excel range was inserted in Word and they both use the same font names and sizes, they look different inside Word ( fonts look as if they stretched a bit)
Styling Cell borders in Excel is not like styling cell borders in Word
I do appreciate any advice on this regards

When you paste as an Excel Worksheet Object, what Word is actually displaying is an image created by Excel. Notice that you can't select any text, for example. Word appears to be distorting the image ever so slightly, so that the fonts won't line up.
Edit: I can't speak for Office 2003, but Office 2007 defaults to the HTML format using PasteExcelTable. The exact macro statement is
Selection.PasteExcelTable False, False, False
This will give formatting that is compatible with Word, but unfortunately the data is not live and won't get updated as the spreadsheet is changed. If your requirements don't include live update, try this method.

Is it possible to have the macro creating a table out of the cells (as normally happens when you manually copy them), rather than inserting an Excel Object.

The best visual results results can be achieved by using Selection.CopyPicture(Appearance, Format); however, you will not be able to edit the data inside Word as you will only get a picture.

Related

Detect Strikethrough in Excel Cell with VB.NET on a Windows Forms App

I am currently writing a program in windows forms with vb.net and an SQL back end. The program is taking customer created Engineering Change Orders, Bill of Material updates, and recreating a custom template that we upload to our Oracle system to create the BOM changes. The customer sends us an excel spreadsheet with the updated BOMs. Items added to the BOM appear in red text and items being removed from the BOM are in red text with a strike through the text. My program is reading down the excel column and adding the item numbers to an SQL table that holds all the new BOMs. My problem is the removed items, items that appear in red with a strikethrough the text, are also being added. I need a way to detect if the font has a strike through so that I can stop them from being added to the SQL table. However, I can't find any way to detect text formatting on the excel sheet. I know you can detect text formatting with VBA inside of an excel macro but I can't find anything on how to do this with VB.NET on windows forms apps.
I thought the code would look something like this however "Characters" is not a legitimate option here.
If xlworksheet.cells(1,1).characters.font.strikethrough = true then
next
end if
Is there anyway to detect text formatting options like strikethrough with VB.NET inside windows forms.
We can use excel interop to do this. We can look for Font.Strikethrough. The following code worked for me.
Dim range as excel.Range = xlworksheet.cells(1,1)
If range.Font.Strikethrough = true then
'Strike through detected, do something
else
'No strike through detected, do something else
End If
The above code looked at the excel cell (1,1) or A1 and checked to see if it had a strike through or not. I confirmed this solution by applying a strikethrough in text on this cell and resaving the file and running the code again without a strike through.

Excel to Word - Formatted with Titles, Heading 1, via ActiveX Check Box

Please see attached image.
I showed a simplified version of what my sheet will be doing. But I will have nearly 100 check boxes, with 100 different topics.
My issue is I want to ONLY show content on the Word Doc when the associated checkbox is "true" on the excel sheet. It must also have 'Heading 1' formatting, and hyperlinks. What is my best path forward?
Have all the content prepopulated in the Word Doc, and have a macro that deletes content that isn't checked in the excel doc?
Start with a blank Word Doc, and populate only content that is checked in Excel.
I have successfully created a way to populate data from excel to word using bookmarks, but not sure how to remove content I don't need.
Thanks so much for your time!
excel to word example

WrapText- Auto format cell height

I am using OpenXML to create reports, I am filling data in existing excel template file.
In excel template 'Wrap text' for all cells is set to true. When my report is complete I open excel file.
In opened file cells are not sized correctly with text wrapping (text wrapping is not applied). Also I observed on machine with office 2007 it works cell are wrapped but on office 2013 cell are not correctly wrapped. If I just double click on any cell then entire row is correctly updated.
Can someone please help me in this, is any property \tag I can set in openXML so that on document open cells are correctly shown.
Previously we were using OLE office interface there it works always so expectation is it should work with openXML too.
Thanks,
Dhanaj

Generating a powerpoint presentation with VBA and Excel

I have a template presentation on powerpoint.
I would like to replace automatically generic placeholders with the value I input in an linked excel worksheet.
I started looking at VBA at the begining of the week, I am not really yet familiar with the syntax, but I am optimistic I will find a way to understand it.
I have put "[ ]" everywhere I want a value input:
the excel sheet present itself like this:
I would like to have some pointers (first, to know if it is indeed possible in powerpoint) to get me started in the right direction.
Does it need to be a PublicSub()?
Am I writing the macro on Powerpoint or in Excel?
Can I use a fonction similar to LookupV to get the values to replace the placeholders?
I would imagine something like :
(side question : can I use regex inside of VBA?)
for each "\[.\]" '(or characterString.startsWith("[")
lookup characterString in excel, return column 3
end each
Would this be possible?
Thank you in advance, I really appreciate the help.
Found an approximate solution, but simpler than code writing.
Open Excel,
fill the values, and copy them onto the powerpoint presentation : use the special paste option between the cell (or cells/cell range) you want.
Choose the "paste the link" option together with object worksheet Excel, select Ok.
Both files will be linked. You can change the values in Excel, and they will change also in powerpoint. The formating is done on excel.
In order to update all the values in the powerpoint after changing them on excel, powerpoint needs to be re-run, and at the restart of the application, accept the updating box prompt.
I find this simpler than the other solutions.

Pasting Excel tables in Thunderbird e-mail client

When I paste an Excel table in Thunderbird e-mail client (ver 24.2.0) the table looses its formatting. One workaround seems to be that you paste the table from Excel to Word and then paste it in Thunderbird. But this seems a bit odd as Word and Excel are part of the same Office Suite of applications, yet their behavior is strange.
Can anybody shed any light on it?
Copy from Excel,
Paste into word -> Paste Options -> Keep Source formatting,
then highlight the table, Go to Design -> on the right, Increase the "Line Weight" to a minimum of 1 point, then click on "Borders" and select "All Borders"
Now copy this table and paste it in your Email. It should work.
The fastest way to copy excel tables as they are, in Thunderbird is to first copy the table to Word, and then recopy and paste within html email.
Colors, lines, format are kept as they are...
Another workaround you can do entirely within Excel is copy the cells for your table, pasted as a picture in Excel and then copy/cut the picture from Excel and then paste to Thunderbird. You lose the ability to edit in place in Thunderbird, and increase the size of the email but you keep all the formatting from Excel.
So far,the best solution is paste the table into Word and then copy from there.
This is a bug from 2003 Reference Link,but didn‘t fix it.
Paste the table as it is in mail from excel, then go to
Format --> Table --> Table Properties
In Borders & Spacing, keep the Borders as- 1 or 2 pixels.
It is working 100%
This is a bug in thunderbird. I overcome this by using LibreOffice (or open office) spreadsheet. Formatting is not lost when we copy from Libreoffice Calc. Thunderbird development is a bit lousy :-). Keeping this bug open for long time.
try to use "Text To column" function under the "DATA" TAB
it will make the column suitable to be pasted as a text

Resources