+ Reply to Thread
Results 1 to 3 of 3

Macro that Copies Table saved as .RTF in Word & Pastes in PowerPoint as Enhanced Metafile

Hybrid View

HRP Macro that Copies Table saved... 11-09-2012, 10:36 AM
HRP Re: Macro that Copies Table... 11-16-2012, 11:24 PM
HRP Re: Macro that Copies Table... 12-05-2012, 10:43 PM
  1. #1
    Registered User
    Join Date
    11-09-2012
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    3

    Exclamation Macro that Copies Table saved as .RTF in Word & Pastes in PowerPoint as Enhanced Metafile

    Hi! I've been trying for days figuring out how to copy a single table saved as Rich Text Format in Word and pasting it in a specific PowerPoint Slide as an Enhanced metafile. What I came across is this code as follows:

    Sub Test()
        Dim WordApp As Object
        Set WordApp = CreateObject("Word.Application")
        With WordApp
    '       Change file name to suit
            .Documents.Open Filename:="D:\file001.rtf"
            .ActiveDocument.Select
            .Selection.Copy
        End With
        ActiveSheet.Range("A1").Select
        ActiveSheet.Paste
        WordApp.Quit
        Set WordApp = Nothing
    End Sub
    However, this code copies a table in Word and pastes it in Excel without the table formatting. I can't find a macro that works specifically for what I need - that is, copy a table in Word, then paste it as an enhanced metafile in PowerPoint. I want the table to be converted to an enhanced metafile because I want to preserve the formatting of the table with lines from Word. Lastly, would it be possible to create a loop such that each table from Word saved as file001.rtf, up to file100.rtf be pasted to slides 1 to 100 respectively in the PowerPoint file, wherein I can also specify a uniform size and position of the pasted tables in PowerPoint? Thank you for your attention and hoping for your immediate response.

    Moderator's Edit: use code tags when posting code. To do so, select your code and click on the # icon at the top of your post window.
    Last edited by arlu1201; 11-17-2012 at 02:24 AM.

  2. #2
    Registered User
    Join Date
    11-09-2012
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macro that Copies Table saved as .RTF in Word & Pastes in PowerPoint as Enhanced Metaf

    Hello again! After modifying codes from various sources, below are the 2 versions of VBA Macro in PowerPoint that solved my problem:

    1. Copies all JPG files in one folder and paste it in separate PPT Slides

    Sub CreatePictureSlideshow()
    'Copy VBA in PowerPoint
    
      Dim presentation
      Dim layout
      Dim slide
    
      Dim FSO
      Dim folder
      Dim file
      Dim folderName
    
      ' Set this to point at the folder you wish to import JPGs from
      ' Note: make sure this ends with a backslash \
      folderName = "D:\Some Directory\"
    
      ' Delete all slides and setup variables
      Set presentation = Application.ActivePresentation
      If presentation.Slides.Count > 0 Then
         presentation.Slides.Range.Delete
      End If
      Set layout = Application.ActivePresentation.SlideMaster.CustomLayouts(1)
      Set FSO = CreateObject("Scripting.FileSystemObject")
    
      ' Retrieve the folder's file listing and process each file
      Set folder = FSO.GetFolder(folderName)
      For Each file In folder.Files
    
         ' Filter to only process JPG images
         If LCase(Mid(file.Name, Len(file.Name) - 3, 4)) = ".jpg" Then
    
            ' Create the new slide and delete any pre-existing contents
            Set slide = presentation.Slides.AddSlide(presentation.Slides.Count + 1, layout)
            While slide.Shapes.Count > 0
              slide.Shapes(1).Delete
            Wend
    
            ' Add the picture
            slide.Shapes.AddPicture folderName + file.Name, False, True, 10, 10
    
            ' Optional: create a textbox with the filename on the slide for reference
            '   Dim textBox
            '   Set textBox = slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 200, 200)
            '   textBox.TextFrame.TextRange.Text = file.Name
         End If
      Next
    
    End Sub
    2. Copies all RTF files in one folder and paste it in separate PPT Slides

    Sub CreateRTFSlideshow()
    'Copy VBA in PowerPoint
    
      Dim presentation
      Dim layout
      Dim slide
    
      Dim FSO
      Dim folder
      Dim file
      Dim folderName
    
      ' Set this to point at the folder you wish to import RTFs from
      ' Note: make sure this ends with a backslash \
      folderName = "D:\Some Directory\"
    
      ' Delete all slides and setup variables
      Set presentation = Application.ActivePresentation
      If presentation.Slides.Count > 0 Then
         presentation.Slides.Range.Delete
      End If
      Set layout = Application.ActivePresentation.SlideMaster.CustomLayouts(1)
      Set FSO = CreateObject("Scripting.FileSystemObject")
    
      ' Retrieve the folder's file listing and process each file
      Set folder = FSO.GetFolder(folderName)
      For Each file In folder.Files
    
         ' Filter to only process RTF files
         If LCase(Mid(file.Name, Len(file.Name) - 3, 4)) = ".rtf" Then
    
            ' Create the new slide and delete any pre-existing contents
            Set slide = presentation.Slides.AddSlide(presentation.Slides.Count + 1, layout)
            While slide.Shapes.Count > 0
              slide.Shapes(1).Delete
            Wend
    
            ' Add the picture
            'slide.Shapes.AddPicture folderName + file.Name, False, True, 10, 10
    
        	Dim WordApp As Object
        	Set WordApp = CreateObject("Word.Application")
        	With WordApp
        	'Change file name to suit
            .Documents.Open FileName:=folderName + file.Name
            .ActiveDocument.Select
            .Selection.Copy
        	End With
    
        	With Slide.Shapes.PasteSpecial(ppPasteMetafilePicture)
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
            .Item(1).ScaleHeight 2, msoCTrue, msoScaleFromMiddle
        	End With
    
            ' Optional: create a textbox with the filename on the slide for reference
            '   Dim textBox
            '   Set textBox = slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 200, 200)
            '   textBox.TextFrame.TextRange.Text = file.Name
         End If
      Next
    
    End Sub
    Hope this helps!
    Last edited by arlu1201; 11-17-2012 at 02:25 AM. Reason: Code tags.

  3. #3
    Registered User
    Join Date
    11-09-2012
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macro that Copies Table saved as .RTF in Word & Pastes in PowerPoint as Enhanced Metaf

    This relates to my earlier post specifically item "2. Copies all RTF files in one folder and paste it in separate PPT Slides". I had a problem with this code because the Word program (Winword.exe under the Task Manager) does not exit after running this macro from PowerPoint even if I placed the following codes before "End Sub":

    
    'Clean up
    WordApp.Quit
    Set WordApp = Nothing
    
    Set layout = Nothing
    Set FSO = Nothing
    Set folder = Nothing
    Set slide = Nothing
    Set presentation = Nothing
    May I kindly request your help on how to exit Word using a PowerPoint macro? TY.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1