Solved

Powerpoint macro for inserting images and text

Posted on 2013-11-28
4
1,176 Views
Last Modified: 2013-11-29
Hello, I have found a very useful powerpoint macro online to auto insert images and text , creidt is given here, http://answers.yahoo.com/question/index?qid=20101102070307AAU3gDh, I have posted the part where the text is added, but I need to modify it to make it larger it only fits one short line of text now, I would like the ability to have up to 3 lines) and I need to add a white background to the text so it can show up against the images'-Thanks!!
'next 4 lines define TextBox(TB) position and dimensions in terms of those of slide
TBPosFromSlideLeftMargin = 0.1 'TB start at 10% of slide width from left to right
TBPosFromSlideTopMargin = 0.8 'TB start at 80% of slide height from top to bottom
TBpercentageOfSlideWidth = 0.8 'TB is 80% of the slide width
TBpercentageOfSlideHeight = 0.2 'TB is 20% of the slide height
Set oDes = oSld.Shapes.AddTextbox( msoTextOrientationHorizontal, _
ActivePresentation. PageSetup.SlideWidth * TBPosFromSlideLeftMargin, _
ActivePresentation. PageSetup.SlideHeight * TBPosFromSlideTopMargin, _
ActivePresentation. PageSetup.SlideWidth * TBpercentageOfSlideWidth, _
ActivePresentation. PageSetup.SlideHeight * TBpercentageOfSlideHeight)
With oDes
.TextFrame.TextRange.Text = picDesc(1)
End With 

Open in new window

0
Comment
Question by:cssoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39683687
Are you actually using Excel to store the text as in the original? If so what does the CSV look like?

Are you adding a picture too? The version of office will help too.

Assuming you need something like the original try

Sub ImportABunchWithTextFromFile()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim picDesc() As String
Dim oSld As Slide
Dim oPic As Shape
Dim oTB As Shape
Dim SW As Long
Dim SH As Long
Dim fs As Object
Dim f As Object
SW = ActivePresentation.PageSetup.SlideWidth
SH = ActivePresentation.PageSetup.SlideHeight
strPath = ActivePresentation.Path
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(strPath & "\book1.txt", 1, 0)
Do While f.AtEndOfStream <> True
picDesc = Split(f.readline, Chr(9))
Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
Set oPic = oSld.Shapes.AddPicture(FileName:=picDesc(0), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0)
Set oTB = oSld.Shapes.AddTextbox(msoTextOrientationHorizontal, _
Left:=SW * 0.1, _
Top:=SH * 0.8, _
Width:=SW * 0.8, _
Height:=SH * 0.2)

With oTB
.TextFrame.TextRange.Text = picDesc(1) & vbCrLf & picDesc(2) & vbCrLf & picDesc(3)
.Fill.ForeColor.RGB = vbWhite
End With
With oPic
.LockAspectRatio = msoTrue
If oPic.Width / oPic.Height > SW / SH Then
.Width = SW
.Top = (SH - oPic.Height) / 2
Else
.Height = SH
.Left = (SW - oPic.Width) / 2
End If
End With
Loop
End Sub
0
 

Author Comment

by:cssoftware
ID: 39684402
Hi and thank you for you assistance! I tried the macro and got
 Runtime error 9 subscript out of range.
I even tried with very short text lines and also the only image that was placed before the error message image did not stretch to fill the slide, here is the macro I am currently running below. (I am actually just using a txt file with a tab stop between the image path and the text for book1.txt like this:
C:\insurance2\6.jpg      Lorum Ipsum

which worked fine, except the text is hard to read without a background, and sometimes I need it to wrap 2-3 lines, and also using powerpoint 2007 )

Sub ImportABunchWithTextFromFile()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As slide
Dim oPic As Shape
strPath = ActivePresentation.Path
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(strPath & "\book1.txt", 1, 0)  'book1.txt need to be "Text(Tab delimited)(*.txt)" when saved in Excel

Do While f.AtEndOfStream <> True
picDesc = Split(f.readline, Chr(9))
Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
Set oPic = oSld.Shapes.AddPicture(FileName:=picDesc(0), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=0, _
Height:=0)
'next 4 lines define TextBox(TB) position and dimensions in terms of those of slide
TBPosFromSlideLeftMargin = 0.1 'TB start at 10% of slide width from left to right
TBPosFromSlideTopMargin = 0.8 'TB start at 80% of slide height from top to bottom
TBpercentageOfSlideWidth = 0.8 'TB is 80% of the slide width
TBpercentageOfSlideHeight = 0.2 'TB is 20% of the slide height
Set oDes = oSld.Shapes.AddTextbox(msoTextOrientationHorizontal, _
ActivePresentation.PageSetup.SlideWidth * TBPosFromSlideLeftMargin, _
ActivePresentation.PageSetup.SlideHeight * TBPosFromSlideTopMargin, _
ActivePresentation.PageSetup.SlideWidth * TBpercentageOfSlideWidth, _
ActivePresentation.PageSetup.SlideHeight * TBpercentageOfSlideHeight)
With oDes
.TextFrame.TextRange.Text = picDesc(1)
End With

With oPic
.ScaleHeight 1, msoTrue
.ScaleWidth 1, msoTrue
End With

With oPic
Dim appssw, appssh
appssw = ActivePresentation.PageSetup.SlideWidth
appssh = ActivePresentation.PageSetup.SlideHeight
.LockAspectRatio = msoTrue
If oPic.Width / oPic.Height > appssw / appssh Then
.Width = appssw
.Top = (appssh - oPic.Height) / 2
Else
.Height = appssh
.Left = (appssw - oPic.Width) / 2
End If
End With
Set oPic = Nothing
Set oDes = Nothing
Set oSld = Nothing
Loop
Set f = Nothing
Set fs = Nothing
End Sub

Open in new window

0
 
LVL 23

Accepted Solution

by:
JSRWilson earned 500 total points
ID: 39684759
That's because I assumed you have three entries for text (one per line) in Excel.

I would NOT use the method for inserting pictures you use. It has never been necessary to specify the width and height and in any version after 2007 will distort the image. It happens to work in 2007 but it isn't correct.

Using MY code you just need to alter this bit:

With oTB
.TextFrame2.WordWrap = True
.TextFrame.TextRange.Text = picDesc(1)
.Fill.ForeColor.RGB = vbWhite
End With
0
 

Author Comment

by:cssoftware
ID: 39685260
Perfect!! Thank you so much and happy holidays!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Q3 of last year, Experts Exchange introduced a new Messaging System, allowing any member to communicate directly with other members. During an especially long thread with a member, I wanted to go back to previous messages in the exchange to re…
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question