PDA

View Full Version : Solved: open a Word doc from ppt and update the doc...



Red2034
10-29-2007, 02:54 PM
need a macro to open a word doc and update it based on textboxes on a ppt slide ... then save the doc.....


anybody...help

Red2034
10-30-2007, 06:46 AM
Sub OpenWordDoc()
'In order to use this code you must set a reference to the
'Word object library by doing this. In the VB Editor click
'Tools, References. Then search for Microsoft Word n.n Object Library
'where n.n will depend on your version of Word.
Dim wdApp As Word.Application, wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open("C:\doc.doc")
wdApp.Visible = True
'You can now do whatever you like with the Word document e.g.
'wdDoc.PrintOut
Dim rngStory As Range
For Each rngStory In ActiveDocument.StoryRanges
With rngStory.Find
.Text = "COURSETITLE"
.Replacement.Text = Slide115.CourseTitle
.MatchCase = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next rngStory

wdDoc.SaveAs "C:\doc.doc"
wdDoc.Activate
End Sub