PowerPoint: Repeat text on every slide - vba

I'm working on creating a PowerPoint template for daily class presentations. In the template I'd like to have a hunk of text that is prominently displayed on the first slide and which repeats at the bottom of the subsequent slides at the bottom in a smaller size. The text will change every day.
The ideas I've had so far:
Use a text field. As far as I can tell, PowerPoint doesn't have anything like a text field that can be dynamically set.
Use a footer - this works and I can modify the master to get the look I want, but I'd really like to be picking up the value of the text from the first page so that edits would be automatically applied and to save the initial step of setting the footer.
Using VBA - I'd be willing to give this a shot, but I've never used VBA and the learning curve seems steep so it would be nice to know if the idea is feasible in VBA.
Can this be done? How would you approach it?
Here's an example of what I'm hoping to be able to do. Ideally the solution would work on both the Mac (2013) and Windows (2016) version of PowerPoint.

You can connect your presentation with an excel file. And running the code in the ppt would pull out the text in the excel file and update the titles instantly.
Create a presentation with a textbox with some temporary text. Put the below code in ppt. save as pptm.
Sub AddMotionPath()
Dim Temp As String
Excel.Application.Workbooks.Open ("D:\Users\Desktop\Book1.xlsx") ' update the path of the excel file
Workbooks("Book1.xlsx").Activate 'activate the file
For p = 1 To 4
Temp = Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("B" & p + 1).Value ' Column B has the titles
ActivePresentation.Slides(p).Shapes(1).TextFrame.TextRange.Text = Temp ' this updates the titles from excel to ppt slide
Next
Excel.Application.Workbooks("Book1.xlsx").Close False 'closes the excel file
End Sub
Let me know if this works for you. You can update the excel file and run the macro in ppt. The text in the slides will be updated automatically.

Related

How to bypass all Excel message boxes with VBA?

I have code that loops through sheets of data and creates charts based on each set of data. That works great. But when I added a line to the code to add a black border to each chart (j is the index used to loop through and identify the appropriate chart):
With ActiveSheet.Shapes("MyChart" & j).Line
.ForeColor.ObjectThemeColor = msoThemeColorText1
End With
Excel displays the following message box for each chart being created when I run the code:
"Complex formatting that is applied to the selected chart may take a while to display. Do you want to continue using the formatting?
Yes/No"
The code works fine if I just keep clicking "Yes" for each chart it's creating until the code is finished, but I don't want Excel to ask this at all, I want it to just go ahead with the formatting.
Everywhere I've looked in my research for how to do this says to set:
Application.DisplayAlerts = False
But this isn't working. Excel still displays the Yes/No box every time. Are there other ways to suppress messages/alerts in Excel? Why isn't the above line of code working?

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

Extract data from content controls in Word to Excel

I have a Word document that is "form-fillable", i.e. it has content control objects in it such as rich text and date picker content controls. I am looking to extract the data from specific fields into Excel. For example, every form has the project title, start date, and manager. I would like 1 row for that form with those three pieces of data. Eventually this will need to be done for a few hundred of these forms every few months, but for now I'd like to just start with one.
I envision having a button on the Excel sheet that will run VBA code to pull the data from the Word document, and populate the proper cells in the sheet. With the filepath for the Word doc being specified by the user.
I am new to VBA. How do I point my code at the right file, and then again at the specific field I need? Do I give the fields titles in the Word doc?
This is in MS Office '13
Your application is going to have a large number of specific details which are difficult to address without the specifics. To get started, here is some very simple code to get the Date from a drop-down in Excel from Word.
Note to work with Word, you need to create a reference to "Microsoft Word 15.0 Object Library" on the Excel side. Tools -> References in the VBA Editor.
When working across applications, it can help to write the VBA in Word and then move it over to Excel once you have the properties you want.
This VBA for the Excel side of the equation:
Sub GetDataFromWordFile()
Dim wrd As Word.Application
Dim file As Word.Document
Set wrd = New Word.Application
Set file = wrd.Documents.Open("test.docx")
Range("A1") = file.ContentControls(1).Range.Text
file.Close
wrd.Quit
End Sub
My Word file includes a single ContentControl. Not sure how you address the ones you want (trial and error?).
The Excel side drops the date in the right place.

How can I add a macro to a Word 2010 or PowerPoint 2010 chart?

In PowerPoint 2010 or Word 2010, when I choose Insert -> Chart, it creates a new chart with an Excel worksheet for the data.
If I add a macro to the Excel worksheet, this seems to be discarded when I close the worksheet and re-open it.
However, it is possible to have a chart with macros, because I also have some Word documents & PowerPoint presentations that I created in Office 2003, which had embedded Excel charts with macros. When I converted those to Office 2010, they look just like "normal" Office 2010 charts, but the macros are preserved.
It looks to me like the embedded chart that gets created when you choose Insert -> Chart is in the "pptx" format rather than the "pptm" format, and so macros are not saved.
(If I query ActiveWorkbook.FileFormat, I get "51", which is "Open Xml Spreadsheet"; this is indeed "pptx", as opposed to "Open Xml Spreadsheet with Macros", which is "52").
How can I insert a chart with the "pptm" behavior? Or change the behavior of an existing chart?
NOTE: I do not want to insert a chart "object", since this means that the chart is not editable within the host application (it merely inserts an Excel chart that you need to "open" in order to edit it).
Let me give you a head start... I can achieve what I want by the following method:
Create a new document in Word (or PowerPoint).
Save the document as a 97-2003 document (which forces it into compatibility mode).
Insert a chart using Insert->Object->Microsoft Excel Chart. This embeds an old-style Excel chart.
Open the embedded chart by right-click->Open, and add a macro.
Close the chart, then choose File->Info and use the Compatibility Mode "Convert" button to convert the document into an Office 2010 document.
Now you have a "native" Word or PowerPoint 2010 chart, which you can edit directly in Word or PowerPoint. If you click on the chart and choose Chart Tools->Design->Edit Data, then the Excel worksheet that opens has the macros you created in step 4. Success!
Now, does anyone have a simpler way?
In my opinion you could achieve what you need in the following way:
(unfortunately, I can't present it with pictures and exact English commands as I'm using local-not English-version of Office)
Choose Insert >> Object >> Object...
In Object window take first page (like Create new)
Search for Microsoft Excel Chart (or something similar) and press
OK
You will get Workbook with two sheets as presented on the picture
below
(there are chart editing feature available on the Ribbon)
Press Alt+F11 while you are in Chart edition like presented in the
picture above. You will get IDE for Excel opened where you will find
appropriate workbook.
Add new module and macro there
Now you could exit chart edition in Word and save document as *.docm
After you will reopen it, go to Chart Edition (double click) >> Alt+F11 >> you will
find you macro there saved within the workbook with *docm extension.
Now that the bounty has passed (with no better answers), I'll add the partial answer from my question, in order to be able to close the question.
Create a new document in Word (or PowerPoint).
Save the document as
a 97-2003 document (which forces it into compatibility mode).
Insert
a chart using Insert->Object->Microsoft Excel Chart. This embeds an
old-style Excel chart.
Open the embedded chart by right-click->Open,
and add a macro.
Close the chart, then choose File->Info and use the
Compatibility Mode "Convert" button to convert the document into an
Office 2010 document.
Now you have a "native" Word or PowerPoint 2010 chart, which you can edit directly in Word or PowerPoint. If you click on the chart and choose Chart Tools->Design->Edit Data, then the Excel worksheet that opens has the macros you created in step 4. Success!
I'm still interested in being able to do this more directly...
The issue is with how the charts data is held within the application. Converting and originating are two different processes. Your data series is basically an array not an excel sheet. It just uses excel to display the data to you to edit. You need to keep your code in the module for powerpoint/word and access the chart via the shapes object if you do not want to embed a excel sheet.
Sub GetChartName()
Dim sSlide As Slide
Dim cChart As Chart
Dim sShape As Shape
Set sSlide = PowerPoint.ActivePresentation.Slides(1)
For Each sShape In sSlide.Shapes
If sShape.HasChart Then
Set cChart = sShape.Chart
MsgBox cChart.Name
Set cChart = Nothing
End If
Next
Set sSlide = Nothing
End Sub