• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 541
  • Last Modified:

Calling Powerpoint Macro from Word Macro

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
cynx
Asked:
cynx
  • 9
  • 9
  • 3
  • +1
1 Solution
 
Chris BottomleyCommented:
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
 
cynxAuthor Commented:
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
 
Chris BottomleyCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
cynxAuthor Commented:
"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
 
cynxAuthor Commented:
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
 
GrahamSkanRetiredCommented:
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
 
Chris BottomleyCommented:
It would be easier if it referred to the filepath rather than embedded the document but yes in theory.

Chris
0
 
Chris BottomleyCommented:
How do you want to proceed?

Chris
0
 
cynxAuthor Commented:
"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
 
Chris BottomleyCommented:
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
 
GlennaShawCommented:
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
 
GlennaShawCommented:
BTW, what is it that you're trying to do with the PPT macro?
0
 
cynxAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
GlennaShawCommented:
See this:
http://skp.mvps.org/pptxp010.htm
But you'll want to complete the sequence and convert it to Word.
0
 
cynxAuthor Commented:
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
 
Chris BottomleyCommented:
You want the DocConvertor sub to work in word, is that correct?

Chris
0
 
cynxAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
cynxAuthor Commented:
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
 
cynxAuthor Commented:
Thanks Chris.
People, for Future Reference: Follow Complete Chain of comments.
0
 
Chris BottomleyCommented:
>>> 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 9
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now