If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > moving text form excel to powerpoint

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-12, 08:32
edoptx edoptx is offline
Registered User
 
Join Date: Aug 2012
Posts: 1
moving text form excel to powerpoint

I have a code to create and move bar graphs from excel to powerpoint and this works great. now i want it to have the code grab text and place it in the same sheet with with the graph.

the text is on sheet 'Questions-all' and the graphs on 'bar graphs' the refference name of the text is on the first column of 'responses'

so the code has to read the name of the "question" from the responses sheet then take that and find the question then take it to the powerpoint.
Code:
Sub CreatePowerPoint() Application.ScreenUpdating = False 
    Calculate 
     
     
     'Add a reference to the Microsoft PowerPoint Library by:
     '1. Go to Tools in the VBA menu
     '2. Click on Reference
     '3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay
     
     'First we declare the variables we will be using
    Dim newPowerPoint As PowerPoint.Application 
    Dim activeSlide As PowerPoint.Slide 
    Dim cht As Excel.ChartObject 
     
     'Look for existing instance
    On Error Resume Next 
    Set newPowerPoint = GetObject(, "PowerPoint.Application") 
    On Error Goto 0 
     
     'Let's create a new PowerPoint
    If newPowerPoint Is Nothing Then 
        Set newPowerPoint = New PowerPoint.Application 
    End If 
     'Make a presentation in PowerPoint
     'If newPowerPoint.Presentations.Count = 0 Then
    newPowerPoint.Presentations.Add 
     'End If
     
     'Show the PowerPoint
    newPowerPoint.Visible = True 
    newPowerPoint.WindowState = ppWindowMinimized 
     
     
     
     'Loop through each chart in the Excel worksheet and paste them into the PowerPoint
    For Each cht In ActiveSheet.ChartObjects 
         
         'Add a new slide where we will paste the chart
        newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText 
        newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count 
        Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count) 
         
         'Copy the chart and paste it into the PowerPoint as a Metafile Picture
        cht.Select 
        ActiveChart.ChartArea.Copy 
        activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select 
         
         'Set the title of the slide the same as the title of the chart
        activeSlide.Shapes(1).TextFrame.TextRange.Text = cht.Chart.ChartTitle.Text 
         
         'Adjust the positioning of the Chart on Powerpoint Slide
        newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 15 
        newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 125 
         
        activeSlide.Shapes(2).Width = 200 
        activeSlide.Shapes(2).Left = 505 
         
         
         'Now let's change the font size of the callouts box
        activeSlide.Shapes(2).TextFrame.TextRange.Font.Size = 16 
         
         
    Next 
     
    AppActivate ("Microsoft PowerPoint") 
    Set activeSlide = Nothing 
    Set newPowerPoint = Nothing 
    Application.ScreenUpdating = True 
End Sub
Attached Files
File Type: zip codingpractice.zip (65.0 KB, 7 views)
Reply With Quote
Reply

Tags
excel, powerpoint, vba

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On