VBA: Copy whole word document to excel - vba

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!

Related

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 - How to read spreadsheet attached to PDF

I have a series of .pdf's which have Excel files attached to them. I want to extract cells "A2:C" & lastline from this spreadsheet.
How do I command VBA to read the attached .xlsx and ignore the .pdf file it is attached to?
Did a lot of searching and no hits so far...
thanks

Paste text into a Word Document with a specific format

I'm working on a macro but I'm stuck at this point. I'm copying text from one word document to another, but I need this text to be pasted in a specific format, neither the source formatting, or it's destination's.
Is it possible to determine that the text I'll be pasting, gets pasted with a specific font, a specific size, and a specific color?
The easiest way to do this would be as follows:
Start recording a new macro.
Paste your text.
Select the pasted text.
Set the formatting (font, size, color) as you require.
Stop recording the macro.
Borrow heavily from the auto-generated selection and formatting code of the new macro for use in your original macro.

excel macro to read text file and find matches in cells

I really could use some help
I have two .txt/csv files that I need to read from into my excel file.
In my excel file I have a whole column, each cell containing string of characters and I need to write a script to be able find matches and and copy an adjacent column from that txt file.
An example of a single row on my txt file is shown below:
"AB101AA","AB10 1AA","AB101A","AB10 1A","AB101","AB10 1","AB10","AB10","AB","10",394251,806376,,
"AB101AF","AB10 1AF","ABERDEEN","ABERDEENSHIRE",,"ABERDEEN, CITY OF"
My excel file would have a cell which probably say "AB101AF" and i want the corresponding cell to run through a million rows and find the match and then find the corresponding nth cell on the txt file and return it on the excel spreadsheet example "ABERDEEN, CITY OF".
I know I havent been helpful in explaining the issue. But any help would be appreciated.
Thank you
Depending upon the size of your text file you could import the file using the GetExternalData option in Excel. This would allow you to load your data into a different Sheet and then use a lookup to your data from the main Sheet. Using Match and/or vlookup should help here.
You could also add a workbook connection to the text file and search using the connection.

format numbers in text box in ppt via 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.