I am trying to write an add-in for Powerpoint, the user should be able to select cells in an Excel worksheet and then go to the Powerpoint slide he would like to paste that table in, after starting the Add-in, a macro should create a table and copy cell by cell. Afterwards the macro will format the PowerPoint table according to our formatting guidelines. I am running into some issues now:
1) How can I go through the cells within a selected range in Excel, I tried to loop through the cells within the selected range, but neither this nor counting the rows/columns with in the selected range works (I am rather unfamiliar with Excel VBA)
2) What is the best way to copy data from Excel to Powerpoint? I have seen some suggestions that use a string array, that reads in all the data first; some users re-use one variable to copy the data and some do it directly from a XL to a PPT reference, what are the advantages of the different approaches?
Thanks a lot
s
For your first question, here is a snippet of code that works (yet, it depends on what you intend to do):
Dim C As Range
For Each C In Range("A1:A100")
'do stuff
Next C
For your second point, it depends on the results you expect :
a PowerPoint formatted array
an Excel Object embedded into PowerPoint
copy-paste the values inside the slide content
Once you have chosen, it's easy to find ressources on the web to do what you want.
Related
I would like to build two workbooks. Workbook A contains a list of animals and pictures as raw data; Workbook B contains a list of animals, and could automatically get their corresponding pictures from Workbook A.
If they were numbers or texts rather than pictures, we could connect the two workbooks by external links (to ranges or names), or by Power Query. But it seems that external links or Power Query don't work with pictures?
Does anyone know how connect two workbooks to achieve this? Does anyone know if it is possible to assign a picture to a cell?
You can use a vlookup-type of setup where the picture changes based on the value entered into a cell. There is an explanation here: https://exceloffthegrid.com/automatically-change-picture/
You'll have to use paste as link or link to picture. I personally cannot test this because Office 365 has paste as link disable right now.
EDIT:
I figured out how to work around Excel.
Insert a Pic
Size it down to the desired cell height/width
Don't click on the pic with the mouse, but move the directional keys with the keyboard (i.e., the green selection [] box) to the cell behind the pic.
Control + C to copy, not the mouse
Pastespecial as linked picture
So, I can't see how you can link them directly but you can use VBA to copy the picture from one workbook to another. You may not like that approach but it's plausible in theory.
Your question regarding whether or not a picture is linked to a cell is a firm yes.
A picture in Excel is classed as a shape. You can loop through each shape and determine if it's a picture or not and then from there, you can copy it from one workbook to another into any cell you care to specify.
The cell the picture resides in can be determined from the TopLeftCell property of the shape itself.
You can test that via this (sandboxed) code below.
Public Sub CopyPictures()
Dim objShape As Shape, objFromSheet As Worksheet, objToSheet As Worksheet
Set objFromSheet = ThisWorkbook.Worksheets("From")
Set objToSheet = ThisWorkbook.Worksheets("To")
For Each objShape In objFromSheet.Shapes
If objShape.Type = msoPicture Then
objShape.CopyPicture
objToSheet.Range(objShape.TopLeftCell.Address).PasteSpecial
End If
Next
End Sub
Open a new workbook and create two sheets, name them "From" and "To".
Copy a few pictures into the "From" sheet and then run the macro.
If you're happy using VBA then the above code will give you a starting point of getting the image from one workbook to another. You just have to fill in the gaps and write the logic around it.
Is it straight forward? Depending the desired outcome, it may very well not be. All possible though with time and effort.
I know that it's not perfect method, but this might help you.
In Workbook A images should be put on specific cell and perfectly located. e.g. C2:
In Workbook B you need to put an image, you can paste any image, then select the picture and put the link to cell of Workbook A as a formula: =[Book1]Sheet1!$C$2
The project I'm working on involves several Outlook VBA procedures that access two Excel workbooks. Without going into too much detail, I am able to access a cell using something like ".Cell(RowNr, 3)" where RowNr is an integer row number.
All columns are named though and I think I ought to be able to use those names in an Outlook VBA procedure (thus ensuring that there will never be a need to insert a new column). I know how to reference a column by name in an Excel macro but haven't been able to find the proper syntax for doing this from an Outlook VBA procedure.
I am assuming you know how to access Excel from Outlook, since you mentioned "several Outlook VBA procedures" that do so. Assuming you have a Worksheet object named sh:
Dim r as Range
set r = sh.Range("<whatever the column name is>")
gives you a reference to that column in r. You can then access r.Cells(i) for the value in the ith row.
I pasted a pivot table from excel to powerpoint and chose the embed option when doing so. The deck is now very large (20MB +) due to the embedded data. Is there a way to keep the table but just drop the embedded data?
The problem is likely because you're copying from a very large Excel workbook. When you embed even one cell from an Excel worksheet, the entire workbook actually gets embedded in the PowerPoint file.
One way around this is to select the information you want to embed, copy/paste it into a new Excel workbook (NOT a new worksheet w/in the workbook), then copy/paste/embed into PPT from the new temporary workbook.
At least this'd work with regular worksheet data; it may not work for Pivot Tables (they'd be dependent on other data that wouldn't get pasted from one worksheet to the other, I'm afraid). But it's worth a shot.
How to quickly copy a whole Excel spread-sheet to another Excel spread-sheet by value? And how to quickly copy some sheets of an Excel spread-sheet to another Excel spread-sheet by value? Without using VBA (Visual Basic for Applications).
For example: suppose I have a spread-sheet called Excel_A with several sheets and with lots of formulas. I want to quickly copy all of Excel_A's values. I want to avoid copying sheet by sheet into another spread-sheet because it will be too slow and there are a lot of sheets in Excel_A.
A simple, dirty workaround, not involving code (which you don't seem inclined to write) is the following:
Save Excel_A As Excel_B
Right-click on one of the sheet handles at the bottom, and click Select All Sheets.
Ctrl-A to Select All, Ctrl-C to copy, Alt E-S-V and Enter to paste values.
Alternatively, it's definitely doable with VBA too. Something similar to the below ought to work. (It assumes both workbooks are open, otherwise replace the names with addresses.)
Sub CopyValuesToNewBook()
Dim wbA As Workbook
Set wbA = Workbooks("Excel_A")
Dim wbB As Workbook
Set wbTest = Workbooks("Excel_B")
For Each Sheet In wbA.Sheets
Sheet.Copy
Dim IndexNo As Integer
IndexNo = Sheets(Sheet).Index
wbB.Sheets(IndexNo).PasteSpecial Paste:=xlValues
Next
End Sub
There is a simple approach that you could follow,
Copy the ranges that you want to copy-paste. Open a new text document and paste it in the txt document. CTRL+A (select all) in the txt file, copy everything and then paste it in the required excel sheet. This would eliminate all the formulas in the cells and would copy just the values in the cell.
If you want to copy the entire sheet, select all (CTRL+A) in that sheet and do the same. You will not be able to copy-paste sheet using the normal way. This can be done sheet by sheet only unless you develop a macro or something else. Hope this helps
In an excel workbook, called workbook A, I set up a connection to another workbook, called workbook B for one particular spreadsheet. This is because I need the worksheet in both locations, and for it to update in the background. That is all set up and working fine, however I want to keep the original formatting. Ive searched the web and tried editing the 'Data' External Data Properties, preserving the cell formatting is enabled. However the data displaying is not in correct format.
Any help would be appreciated.
Paste twice is required.
1) Paste link
2) Paste format
See link below:
http://www.excelforum.com/excel-general/500227-how-do-i-paste-links-and-keep-formats.html