Link to home
Start Free TrialLog in
Avatar of cynx
cynxFlag for India

asked on

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 ?
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of cynx

ASKER

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.
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
Avatar of cynx

ASKER

"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
Avatar of cynx

ASKER

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
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.
It would be easier if it referred to the filepath rather than embedded the document but yes in theory.

Chris
How do you want to proceed?

Chris
Avatar of cynx

ASKER

"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
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
Avatar of GlennaShaw
GlennaShaw

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
BTW, what is it that you're trying to do with the PPT macro?
Avatar of cynx

ASKER

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.  !
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
See this:
http://skp.mvps.org/pptxp010.htm
But you'll want to complete the sequence and convert it to Word.
Avatar of cynx

ASKER

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
You want the DocConvertor sub to work in word, is that correct?

Chris
Avatar of cynx

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cynx

ASKER

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

Avatar of cynx

ASKER

Thanks Chris.
People, for Future Reference: Follow Complete Chain of comments.
>>> 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