format numbers in text box in ppt via vba - vba

I have connected Excel and Powerpoint via VBA to send values from the Excel sheet to the PPT.
All is working well except one thing: I need to transfer values from cells in Excel to text box shapes in ppt while preserving the number formatting from excel. How do I do that?
I do this for about 10 such boxes and my current code using copy from excel and paste in powerpoint, keeps on giving out of range error on random places.
Will paste the code I am using in a short while.

Try using the numberFormat from Excel when you bring over the Value.
Example:
With Workbooks(1).Sheets(1).Range("A1")
valueToPaste = Format(.Value, .NumberFormat)
End With
For the sake of the example, I'm pretending you are calling this from Excel and only want to know how to extract the value with it's format. We are using the first sheet of the first workbook in Range A1. It should be easy enough to update to your specific needs.
There are probably some exceptions, particularly for custom formats, but this should work for the majority of formats you would use in Excel.

Related

PowerPoint VBA - extending chart data range

I am trying to create a VBA macro in PowerPoint that will extend the range of an excel embedded chart to the last row with data. How can this be achieved?
You can use "lastrow," which is expressed as an integer.
Table.LastRow
So, depending on your slide, you might say something like
ActivePresentation.Slides(3).Shapes(5).Table.lastRow
to get the last row number.

VBA: Copy whole word document to excel

I´m trying to simply copy whole word document into excel and keep the source formatting (and images).
Assuming both documents are open.
I tried this code:
Sheets("Nabídka").Range("A" & 87) = Documents("K4E pila.docx").Range.Text
but it only copies the text without formatting and images. Is there a similar command which includes the formatting?
Even If I copy/paste from word to excel (ctrl+c) the formatting is ruined --> The image overlaps the text.
This is the first step I need to figure out to proceed in my project. The outcome should be: Copy all word documents into excel if the name of the word document matches some excel cells values.
Thanks in advance for any help!

Pasting an Excel chart into a Word document so it is editable but not linked

I'm using VBA to create a series of charts in Excel and then copying them into a Word file.
Up till now I've been pasting the charts as pictures, so in Excel I used
ActiveChart.CopyPicture
and then in Word, after selecting the target location:Selection.Paste.
Now I want to change it so the charts will be editable but not linked to the source Excel file.
I copy a chart from Excel using ActiveChart.ChartArea.Copyand look at the paste-special options in Word, the options "use destination theme/keep source formatting & embed workbook" work fine for me:
the chart is editable (also the data is editable which I don't need but is OK) and there is no link to the original Excel file.
BUT - I can't find how to perform this through VBA code. Trying to record this in a macro only give me Selection.Paste - which pastes a linked chart.
I also tried a different approach - pasting a linked chart, and then killing the link. once again, deleting the links in the link editor doesn't get recorded in the macro at all.
Please help with coding any of these two options or suggesting a different approach.
The Range.PasteAndFormat method should work. This takes a WdRecoveryType Enum parameter that lets you specify what kind of result you want.
Selection.PasteAndFormat(wdChart) 'Enum value 14 in case of late binding

VBA code to clear FORMATTING and leave plain text data in a chosen column in Excel

I need to create a button to add to Excel (2010 currently) that will strip all the formatting in that column and just leave plain text. Our current solution is to copy the data into Notepad to strip out the formatting and then copy it back in from Notepad. This works, but is inelegant and would be far easier if I could just create a button to do this within Excel itself. I've seen a few solutions posted but none of them seem to deal with a randomly selected column. Help!
The Range.ClearFormats method seems appropriate here.
With Worksheets("Sheet1")
.Columns(1).ClearFormats 'clear formatting from column A
End With
'for a manually selected group of cells
Selection.ClearFormats 'clear formatting from the cells currently selected
fwiw, the Clear Formats command is available on the ribbon through Home ► Editing ► Clear ► Clear Formats (Alt+H+E+F). You could easily add that command to the QAT rather than create a macro that largely duplicates the command and assign it to a custom button.
Excel already has a button on the Home tab:
Just select the entire column and click Clear Formats
Just to add to Jeeped's answer:
Using this code you'll clear the whole columns formatting (select a random cell, run this code and the whole columns formatting has been cleared)
Sub ClearColumn()
i = ActiveCell.Column
ActiveSheet.Columns(i).ClearFormats
End Sub

vba command to paste special KeepSourceFormatting(K) in powerPoint

i am trying to take a cell range from excel and copy it to powerpoint2010. However I do not want to use the Embedded format but rather the KeepSourceFormatting one. I tried the following command
ActiveWindow.View.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse
but this still creates an object that launches excel to edit the contents.
basically I want to paste a table of formated data from excel to powerpoint and maintain its appearance but still be able to edit the contents in powerpoint.
any ideas?
There are following options for DataType:
ppPasteEnhancedMetafile which allows edition each of separate field of the table (rather pure solution)
ppPasteMetafilePicture similar option
ppPasteOLEObjectwhich you know
I can't see any other option.