Solved

Calling Powerpoint Macro from Word Macro

Posted on 2009-04-08
22
530 Views
Last Modified: 2013-11-25
Senario:
I have developed a macro in word to search specific words for multiple word documents and generate a report in word.
Since this tool works only with .doc and .docx files.
To scan the .ppt files for the same i need to convert them to word first.
I wrote a macro in powerpoint to extract text from ppt and store it in word, which can be later scanned using my previous tool

Question:
I need to call this powerpoint macro from my word doc, each time the button in the word doc is pressed. How can this be done ?

Since i wont be shipping the powerpoint with my tool which is word, can i insert it as object in word doc tool and call macro from it ? if yes how ?
0
Comment
Question by:cynx
  • 9
  • 9
  • 3
  • +1
22 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24094613
Whilst there a few concerns over PPT automation from other applications I have seen it work in each case up till now.

Your code ought to be viable to reform for use from word but depending on it's complexity may take a while.  It will however always require that the user have ppt installed in order to work.

Chris
0
 
LVL 1

Author Comment

by:cynx
ID: 24094636
yes user system will have ppt installed. my concern is since my tool is called from word doc, to call the ppt macro, there shouldnt be necessity to refer the ppt file which resides on system, rather would prefer integrated / inserted into my word doc.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24094752
DOn't quite understand but are you saying that you want the ppt embedded into the word document and then to run the PPT macro from word and on the embedded ppt file?

Chris
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:cynx
ID: 24094783
"I need to run a ppt macro from a word document."

You can suggest any method to achieve the above.

My concern is, incase we need to have ppt file/ reference to the ppt file to achieve the above, i would like the ppt to be inserted in my word doc rather than refering the path of external ppt.

I hope this was helpful

Thanks

Mehul
0
 
LVL 1

Author Comment

by:cynx
ID: 24094789
The ppt files "on which" the ppt macro will run are being selected by a file explorer from my ppt macro. Hence thats not the concern.

Mehul
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 24094853
It is possible to embed an unlinked Powerpoint presentation in a Word document. As you are probably aware, you will need Powerpoint to be installed on the target system if you need to display it and to run code.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24094976
It would be easier if it referred to the filepath rather than embedded the document but yes in theory.

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24099554
How do you want to proceed?

Chris
0
 
LVL 1

Author Comment

by:cynx
ID: 24104752
"I would like to call the macro from embedded ppt if possible."

With external path referral i tired out yesterday, it works. but thats not what i require.

I also tried placing my powerpoint code in Auto_Open, and inserted powerpoint as object in my word doc. But since Powerpoint dosnt support Auto Play of macro when its opened, its of no use.[auto play in powerpoint only supported with .ppa , powerpoint template i guess]

Mehul
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24105351
I've had a 'firkle' with an embedded ppt in a word document and I cannot see how to do it so i'll leave you to see if someone else can help.

Chris
0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 24106563
You are correct, PowerPoint does not include the ability to autorun a macro.  It doesn't matter whether the PP file is embedded or not.
See: http://skp.mvps.org/autoevents.htm
0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 24106580
BTW, what is it that you're trying to do with the PPT macro?
0
 
LVL 1

Author Comment

by:cynx
ID: 24107363
my PPT macro converts the PPT file to WORD doc , so that it can be scanned by my Word macro tool(which works only on .doc)
To extend the support to PPT files, I first convert them to DOC (using my PPT macro Tool) and Later they can be scanned.

currently i have to do ppt > word conversion part seperately by running the ppt macro. I want it to run from my Word macro tool itself by the click of one button !

OR if you can provide a method/macro in WORD VBA programming to convert ppt > doc ( extract text from ppt),  that too will solve my problem.  !
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24107621
It should be possible to convert the macro to work from word .. can you provide a sample word and PPT file to work with?

The concept I am looking to is to trigger the conversion from Word and then access the resultant by whatever means the current PPT macro saves the text.

Chris
0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 24111354
See this:
http://skp.mvps.org/pptxp010.htm
But you'll want to complete the sequence and convert it to Word.
0
 
LVL 1

Author Comment

by:cynx
ID: 24136419
I have attached sample Word and Ppt Macro i have been working on.

The ppt macro: Is it possible to rewrite the same in word, defining same functionality ?


WordMacro.txt
pptMacro.txt
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24136554
You want the DocConvertor sub to work in word, is that correct?

Chris
0
 
LVL 1

Author Comment

by:cynx
ID: 24136570
Yep ! If thats possible, In one click i can select a ppt file > Convert to Doc > Scan for words > generate a report...as it works for doc files, all in one go !!

Mehul
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 24138895
The following should be your code modified to run as is from a word code module
Sub DocConvertor()
Dim pptApp As Object
Dim strFolderName As String
Dim oPres As Object
Dim oSlides As Object
Dim oSld As Object
Dim oShp As Object
Dim iFile As Integer      'File handle for output
Dim PathSep As String
Dim FileNum As Integer
Dim Path As String
Dim FileName As String
Dim Prompt As String
Dim Title As String
Dim ppt As Object
  
  iFile = FreeFile          'Get a free file number
  Set pptApp = CreateObject("powerpoint.application")
 
 #If mac Then
    PathSep = ":"
  #Else
    PathSep = "\"
  #End If
  
   Prompt = "Select the folder with the files that you want to search through."
    Title = "Folder Selection"
    MsgBox Prompt, vbInformation, Title
     
    Path = BrowseFolder("Select A Folder")
    If Path = "" Then
        Prompt = "You didn't select a folder. The procedure has been canceled."
        Title = "Procedure Canceled"
        MsgBox Prompt, vbCritical, Title
GoTo Canceled:
    End If
 
FileName = Dir(Path & "\*.ppt", vbNormal)
    'Do Until FileName = ""
     '  On Error Resume Next
        pptApp.Presentations.Open Path & "\" & FileName, ReadOnly:=True
     ' If Err <> 0 Then
 
      '  End If
       ' On Error GoTo 0
              Set oPres = pptApp.ActivePresentation
  Set oSlides = oPres.Slides
            
  FileNum = FreeFile
 
  'Open output file
  ' NOTE:  errors here if file hasn't been saved
  Open oPres.Path & PathSep & "AllText.Doc" For Output As FileNum
 
  For Each oSld In oSlides    'Loop thru each slide
    For Each oShp In oSld.Shapes                'Loop thru each shape on slide
 
      'Check to see if shape has a text frame and text
      If oShp.HasTextFrame And oShp.TextFrame.HasText Then
        If oShp.Type = msoPlaceholder Then
            Select Case oShp.PlaceholderFormat.Type
                Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
                    Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderBody
                    Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderSubtitle
                    Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
                Case Else
                    Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.TextRange
            End Select
        Else
            Print #iFile, vbTab & oShp.TextFrame.TextRange
        End If  ' msoPlaceholder
      End If    ' Has text frame/Has text
 
    Next oShp
  Next oSld
 
  'Close output file
  Close #iFile
             'Loop
            
Canceled:
     
    Set ppt = Nothing
    oPres.Close
    pptApp.Quit
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:cynx
ID: 24145573
Was Recieving Run-time Error : The Powerpoint Frame window does not Exist.

Inserted   "pptApp.Visible = True" before      
                 "pptApp.Presentations.Open Path & "\" & FileName, ReadOnly:=True"

This rectified the problem. Yes the Macro works perfectly fine for Word. This solves my problem !

Thanks Chris for the quick Help.

Mehul
Sub DocConvertor()
Dim pptApp As Object
Dim strFolderName As String
Dim oPres As Object
Dim oSlides As Object
Dim oSld As Object
Dim oShp As Object
Dim iFile As Integer      'File handle for output
Dim PathSep As String
Dim FileNum As Integer
Dim Path As String
Dim FileName As String
Dim Prompt As String
Dim Title As String
Dim ppt As Object
  
  iFile = FreeFile          'Get a free file number
  Set pptApp = CreateObject("powerpoint.application")
 
 #If mac Then
    PathSep = ":"
  #Else
    PathSep = "\"
  #End If
  
   Prompt = "Select the folder with the files that you want to search through."
    Title = "Folder Selection"
    MsgBox Prompt, vbInformation, Title
     
    Path = BrowseFolder("Select A Folder")
    If Path = "" Then
        Prompt = "You didn't select a folder. The procedure has been canceled."
        Title = "Procedure Canceled"
        MsgBox Prompt, vbCritical, Title
GoTo Canceled:
    End If
 
FileName = Dir(Path & "\*.ppt", vbNormal)
    'Do Until FileName = ""
     '  On Error Resume Next
        pptApp.Visible = True
        pptApp.Presentations.Open Path & "\" & FileName, ReadOnly:=True
     ' If Err <> 0 Then
 
      '  End If
       ' On Error GoTo 0
              Set oPres = pptApp.ActivePresentation
  Set oSlides = oPres.Slides
            
  FileNum = FreeFile
 
  'Open output file
  ' NOTE:  errors here if file hasn't been saved
  Open oPres.Path & PathSep & "AllText.Doc" For Output As FileNum
 
  For Each oSld In oSlides    'Loop thru each slide
    For Each oShp In oSld.Shapes                'Loop thru each shape on slide
 
      'Check to see if shape has a text frame and text
      If oShp.HasTextFrame And oShp.TextFrame.HasText Then
        If oShp.Type = msoPlaceholder Then
            Select Case oShp.PlaceholderFormat.Type
                Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
                    Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderBody
                    Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
                Case Is = ppPlaceholderSubtitle
                    Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
                Case Else
                    Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.TextRange
            End Select
        Else
            Print #iFile, vbTab & oShp.TextFrame.TextRange
        End If  ' msoPlaceholder
      End If    ' Has text frame/Has text
 
    Next oShp
  Next oSld
 
  'Close output file
  Close #iFile
             'Loop
            
Canceled:
     
    Set ppt = Nothing
    oPres.Close
    pptApp.Quit
End Sub 

Open in new window

0
 
LVL 1

Author Closing Comment

by:cynx
ID: 31567904
Thanks Chris.
People, for Future Reference: Follow Complete Chain of comments.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24148667
>>> pptApp.Visible = True

You're quite correct and I apologise.  From my experience so far it is possible to do it without PPtApp being visible but it's so much easier if it is, (and I didn't pursue this as it wan't requested).

Chris
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

 Regular Expressions Microsoft Word has sophisticated search tools that can search for patterns. For example if you wanted to search for all UK phone numbers that followed a pattern of five digits, a space and then six digits you can easily do th…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now