VBA automating Word from PowerPoint 11-22-09

I have an add-in macro that exports PPT content to a new Word document for 
each PPT file in the same folder as the currently open PPT file. I've noticed 
that when the macro is finished, and I go to Word, Word seems "paralyzed" (I 
can't use any menu commands or close the doc). If I Alt+Tab back to 
PowerPoint, and then Alt+Tab back to Word, all is well.  Is there something 
about automating Word from PowerPoint that needs to be "cleared" when the 
PowerPoint macro ends - some way to release PowerPoint's control over Word?

I found http://www.pptfaq.com/FAQ00795.htm (and related items on 
pptfaq.com), but don't see anything that specifically addresses terminating 
control of one application from another. I also downloaded the Office 
Automation Help from Microsoft and read about destroying an automation object 
variable, but I'm not sure I have one (at least it doesn't look like the 
example in the Help).

I'm using Office 2002 SP3.

Here's what I have so far:

Sub ExportTOCToWord()
Dim rayFileList() As String
Dim strFolderPath As String
Dim FileSpec
Dim strTemp As String
Dim X As Long
Dim oPres As Presentation 'used to define strFolderPath
Dim strFullTOC As String
Dim PathSep As String
Dim aTemp As Template
Dim MyDoc As New Word.Document
Dim strMyFile As String 'defines file name for SaveAs
Dim strTemplateFullName As String 'path to toc.dot template and filename 
toc.dot

Set oPres = ActivePresentation
PathSep = "\"
strFolderPath = oPres.Path & PathSep
FileSpec = "*.ppt"

' Fill the array with files that meet the spec above
ReDim rayFileList(1 To 1) As String
strTemp = Dir$(strFolderPath & FileSpec)

While strTemp <> ""
    rayFileList(UBound(rayFileList)) = strFolderPath & strTemp
    ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As String
    strTemp = Dir
    'Debug.Print strTemp
Wend

' array has one blank element at end - don't process it
' don't do anything if there's less than one element
If UBound(rayFileList) > 1 Then
    For X = 1 To UBound(rayFileList) - 1
        Call ForEachPPT(rayFileList(X))
        'Debug.Print strTOC 'Prints full TOC WITH empty paragraphs between 
modules
        strFullTOC = strFullTOC & strTOC
        'Debug.Print strFullTOC 'Prints full TOC WITHOUT empty paragraph 
between modules
    Next ' x
End If
        
    'Define file name for Word doc and use same path as the active PPT 
presentation
    strMyFile = ActivePresentation.Path & "\toc.doc"
    'Debug.Print strMyFile
    
    On Error Resume Next
    
    With MyDoc
        .Application.Visible = False
        .Application.ScreenUpdating = False
        .ActiveWindow.View.Zoom.PageFit = wdPageFitFullPage
        Set aTemp = .AttachedTemplate 'Get full name and path of default 
template Normal.dot
        strTemplateFullName = GetPath(aTemp.FullName) & "toc.dot"

        'Create a Word doc based on the toc.dot template
        Word.Documents.Add Template:=strTemplateFullName
        
        Word.Application.Visible = True
        Word.Application.ScreenUpdating = True
        Word.ActiveDocument.SaveAs strMyFile
        
        With Word.ActiveDocument
            'Find the placeholder text "Paste TOC.txt here" and select it
            With Selection.Find
                .Forward = True
                'ClearFormatting prevents applying whatever
                'the most recent settings were in the Find and Replace 
dialog box
                .ClearFormatting
                .MatchWholeWord = True
                .Wrap = wdFindContinue
                .Execute FindText:="Paste TOC.txt here"
            End With
            Selection.Text = strFullTOC        
            Selection.HomeKey Unit:=wdStory
           
        'Reset style of last 3 paragraphs (one is the section break) to TOC 2
        .Content.Paragraphs.Last.Range.Style = "TOC 2"
        .Content.Paragraphs(.Content.Paragraphs.Count - 2).Range.Style = 
"TOC 2"
        
        End With 'ActiveDocument
        Word.Documents("toc.doc").Save
        MyDoc.Close
    End With
End Sub

0
Utf
11/22/2009 3:38:01 AM
powerpoint 2011 articles. 0 followers. Follow

1 Replies
994 Views

Similar Articles

[PageSpeed] 23

Please stick to one thread, there is an answer in your original question.
-- 
john ATSIGN PPTAlchemy.co.uk

Free PPT Hints, Tips and Tutorials
http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html






"caten" wrote:

> I have an add-in macro that exports PPT content to a new Word document for 
> each PPT file in the same folder as the currently open PPT file. I've noticed 
> that when the macro is finished, and I go to Word, Word seems "paralyzed" (I 
> can't use any menu commands or close the doc). If I Alt+Tab back to 
> PowerPoint, and then Alt+Tab back to Word, all is well.  Is there something 
> about automating Word from PowerPoint that needs to be "cleared" when the 
> PowerPoint macro ends - some way to release PowerPoint's control over Word?
> 
> I found http://www.pptfaq.com/FAQ00795.htm (and related items on 
> pptfaq.com), but don't see anything that specifically addresses terminating 
> control of one application from another. I also downloaded the Office 
> Automation Help from Microsoft and read about destroying an automation object 
> variable, but I'm not sure I have one (at least it doesn't look like the 
> example in the Help).
> 
> I'm using Office 2002 SP3.
> 
> Here's what I have so far:
> 
> Sub ExportTOCToWord()
> Dim rayFileList() As String
> Dim strFolderPath As String
> Dim FileSpec
> Dim strTemp As String
> Dim X As Long
> Dim oPres As Presentation 'used to define strFolderPath
> Dim strFullTOC As String
> Dim PathSep As String
> Dim aTemp As Template
> Dim MyDoc As New Word.Document
> Dim strMyFile As String 'defines file name for SaveAs
> Dim strTemplateFullName As String 'path to toc.dot template and filename 
> toc.dot
> 
> Set oPres = ActivePresentation
> PathSep = "\"
> strFolderPath = oPres.Path & PathSep
> FileSpec = "*.ppt"
> 
> ' Fill the array with files that meet the spec above
> ReDim rayFileList(1 To 1) As String
> strTemp = Dir$(strFolderPath & FileSpec)
> 
> While strTemp <> ""
>     rayFileList(UBound(rayFileList)) = strFolderPath & strTemp
>     ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As String
>     strTemp = Dir
>     'Debug.Print strTemp
> Wend
> 
> ' array has one blank element at end - don't process it
> ' don't do anything if there's less than one element
> If UBound(rayFileList) > 1 Then
>     For X = 1 To UBound(rayFileList) - 1
>         Call ForEachPPT(rayFileList(X))
>         'Debug.Print strTOC 'Prints full TOC WITH empty paragraphs between 
> modules
>         strFullTOC = strFullTOC & strTOC
>         'Debug.Print strFullTOC 'Prints full TOC WITHOUT empty paragraph 
> between modules
>     Next ' x
> End If
>         
>     'Define file name for Word doc and use same path as the active PPT 
> presentation
>     strMyFile = ActivePresentation.Path & "\toc.doc"
>     'Debug.Print strMyFile
>     
>     On Error Resume Next
>     
>     With MyDoc
>         .Application.Visible = False
>         .Application.ScreenUpdating = False
>         .ActiveWindow.View.Zoom.PageFit = wdPageFitFullPage
>         Set aTemp = .AttachedTemplate 'Get full name and path of default 
> template Normal.dot
>         strTemplateFullName = GetPath(aTemp.FullName) & "toc.dot"
> 
>         'Create a Word doc based on the toc.dot template
>         Word.Documents.Add Template:=strTemplateFullName
>         
>         Word.Application.Visible = True
>         Word.Application.ScreenUpdating = True
>         Word.ActiveDocument.SaveAs strMyFile
>         
>         With Word.ActiveDocument
>             'Find the placeholder text "Paste TOC.txt here" and select it
>             With Selection.Find
>                 .Forward = True
>                 'ClearFormatting prevents applying whatever
>                 'the most recent settings were in the Find and Replace 
> dialog box
>                 .ClearFormatting
>                 .MatchWholeWord = True
>                 .Wrap = wdFindContinue
>                 .Execute FindText:="Paste TOC.txt here"
>             End With
>             Selection.Text = strFullTOC        
>             Selection.HomeKey Unit:=wdStory
>            
>         'Reset style of last 3 paragraphs (one is the section break) to TOC 2
>         .Content.Paragraphs.Last.Range.Style = "TOC 2"
>         .Content.Paragraphs(.Content.Paragraphs.Count - 2).Range.Style = 
> "TOC 2"
>         
>         End With 'ActiveDocument
>         Word.Documents("toc.doc").Save
>         MyDoc.Close
>     End With
> End Sub
> 
0
Utf
11/22/2009 8:32:01 AM
Reply:

Similar Artilces:

Stopping word split lines over pages
Hi All, I wonder whether you knowledgeable folk can help me... I'm really stuck with this one and it's driving me slightly crazy. I'm re-typing/ editing a theatre script in word. It's formatted so that the Character's name who is speaking is on one line and then directly below is there dialogue. There is then 2 line breaks before the next section of dialogue... E.g: SAM Hello There how are you? JOHN I'm fine thanks... How was your day? SAM Good... (etc. etc.) What I want to stop work from doing is splitting the Character's name and the li...

A Newbie question. Input value and have return inserted in Word
I have a listing of numbers with names/addresses in Excel and would like to be able to enter a number and have the corresponding info returned into a Word merge file. Is this possible? Any help would be greatly appreciated. Tks ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ ...

VBA code to say Yes or No if any VBA code is present in ActiveWork
Using XL 2003 & 97 Would like hit Ctrl+Shift+V and have an answer either yes or no as to the presence of Any VBA code in the Active Workbook. I do know that about the VBA editor/Explorer or to press the Run Macro button and get a list from various sources . I would like to stay at the keyboard and process a series of macros including one to let me know if I even need to evoke the VBA explorer. TIA Dennis There is no bootstrap macro to tell you whether you have macros or not. If there were there would be no limit to virus writers. --- HTH, David McRitchie, Microsoft MVP - Excel ...

I keep having to force quit MS Word It also Freezes screen often
Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I keep having to force quit MS Word. It won't quit when I hit quit. It also seems to Freeze the screen often and I have to restart. Help? Without having so much as an indication what version of Office you're using it's impossible to suggest anything other than the fundamentals; 1- Make sure your version of Office is fully updated, 2- Make sure OS X is fully updated, 3- Run Disk Utility - Repair Disk Permissions, 4- Restart your Mac. If you continue to have a problem reply here with version specific in...

Print, Merged Cells, and VBA
Hello I'm looking for a code that will help me with a print job for a worksheet. There are a lot of merged cells and a lot of "IF"s to be used in the VBA for range selection. Thanks in advance, Sarr ...

Shared calendar with some automation
Hi all, is it possible to set up a public calendar in Exch that does the following: Every time that a user (who belongs to a specified A.D. user group) posts a meeting/appointment to his\her personal calendar (the one one on the individual mailbox) if the appointment is public (vs. private) that appointment is automatically copied/replicated to a shared/public calendar that all the users of the AD group can see. Is it possible to set up something in Exchange or/and Sharepoint that does this? Would this entail writing some specific code or can it be accomplished with standard...

Use VBA to update Access table or Query from Excel
Can I use VBA to update Access table or Query from Excel? Thanks in advance Hi Leungkong, > Can I use VBA to update Access table or Query from Excel? Of course, using ADO or DAO. See: http://www.erlandsendata.no/english/index.php?d=envbadacexportado Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com Hi Jan, Thanks. I think ADO is what I want. But I am not only want to export from excel to access. I want to edit some data in access table. For example, Access has a table "ProductList" I want to use Excel to call the product by "Pro...

VBA and Scheduled task in Outlook
Hi, how can I: a) pull the query from somewhere and send it by e-mail automatically. E.g. I want to take a temperature table from http://www.wunderground.com/history/airport/EHAM/2009/7/10/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA where 2009/7/10 is the date of yesterday put it into an e-mail and send it automatically each day at 8 o'clock? b) if this is not possible, how can I send an e-mail with the attachment c:\Documents\query20090710.xls each day at 8 o'clock? my boss wants this automatized, I know how to write the VBA code for Excel, but don'...

New G5 tower has problem opening Word 2004
I have a brand new G5 running OSX 10.4.10. I have installed Office 2004, and am having trouble launching Word. After double clicking, it opens a blank window and then freezes as it works it way through the "optomizing font performance" bar at the bottom of the window. <br><br>It starts to give me a warning box for one font after another that says "This font is corrupt and should be removed." I believe, however, that Word itself it installing the fonts in Font Book just before it determines they are corrupt. Wierd. <br><br> It has taken me over 1/2 ho...

Dex 11 error
I am getting the flowing error when using test mode. This error occurs before the login screen appears and when error I click the server drop down. Has anybody ran into this error before? Unhandled script exception: Could not load external 'DexIsODBCsqlDriver@GPDWIN32.dll'. EXCEPTION_CLASS_SCRIPT_MEMORY SCRIPT_CMD_EXTERN Reinstalling the application will help. -- Regards, -- Mohammad R. Daoud MVP, MCP, MCBMSP, MCTS, MCBMSS Mob: +962 - 79 -999 65 85 mohdaoud@gmail.com http://mohdaoud.blogspot.com/ "Jason" <Jason@discussions.microsoft.com&...

vba select field
Hi, having a button on a form, is it possible to select only some fields (all from the same table) of the current record instead of all fields? I've tried this code: RunCommand acCmdSelectRecord RunCommand acCmdCopy Forse dipende dei dati nel record. but it selects ALL fields in the form. Thank you. Remigio hi, On 10.04.2010 18:01, remigio wrote: > having a button on a form, is it possible to select only some fields > (all from the same table) of the current record instead of all fields? > I've tried this code: > > RunCommand acCmdSelectRecord &...

VLOOKUP in VBA
On the worksheet I can insert in a cell =VLOOKUP(C5, Hobokee.xls!AcsLow, 2) and it works perfectly, looks up the value in column 2 of the range named AcsLow in the same workbook. But elswhere I want in a macro to lookup the same table and assign the result to a variable BalAmt. BalAmt = VLOOKUP(AccNum, Hobokee.xls!AcsLow, 2) does not work. It gives a function not defined error on Hobokee. If instead of Hobokee I put Workbooks("Hobokee"), it gives function not defined error for VLOOKUP which it changes to VLookup. I have been overVLOOKUP in the Help file and see nothing wrong. W...

Automated form filling from a list
Hi all, I have a report that needs to be filled and printed. 500 of those reports. Data for them is in a sheet in form of a table. What I need to do is to take a row from one sheet, put the data in another sheet in correct places, print it, take next row, print it etc. Any idea how can I do it using Excel only ? Plan B is to make an application that using automation will do it using those 2 sheets. But I would prefer to do it simple as possible. I would appreciate any concepts. Best Regards Pawel Why not just use Mail Merge in Word? Pees wrote: > Hi al...

Excel VBA/Macro programming for beginners
Hi all, I know a bit VB 6.0 programming. Will it help me to write exce vba/macro(same thing?).can anybody help me by providing some fre websites where i can have informations/codes for VBA/macro. Please tell me how could i make a *command Button * in a cell in th excel sheet -- sdebu_200 ----------------------------------------------------------------------- sdebu_2000's Profile: http://www.officehelp.in/member.php?userid=430 View this thread: http://www.officehelp.in/showthread.php?t=118812 Posted from - http://www.officehelp.i Try David McRitchie's "getting started with mac...

WDM to WinCE porting 11-17-09
Hi i am working on a driver for a Ni's PCI based card. i have a reference WDM driver code for the card, i am porting most of the code and re writing some code. i need to implement the following code in CE. m_pMDL = IoAllocateMdl ( a_pMemory, (ULONG) a_ByteCount, FALSE, TRUE, NULL ); MmProbeAndLockPages ( m_pMDL, UserMode, IoModifyAccess ); m_pLockedKernelBuffer = MmGetSystemAddressForMdlSafe ( m_pMDL, NormalPagePriority ); i have no prior experience in WDM drivers and...

Turn pc speaker on/off with vba code
Is this possible? Thanks I found something here on how to do it withVBScript. You can probably modify it to work in VBA http://www.pcreview.co.uk/forums/thread-1468591.php -- HTH, Barb Reinhardt "David" wrote: > Is this possible? > Thanks Thanks Barb I'll have a go (I need to improve my web searching skills) "Barb Reinhardt" wrote: > I found something here on how to do it withVBScript. You can probably modify > it to work in VBA > > http://www.pcreview.co.uk/forums/thread-1468591.php > -- > HTH, > ...

Loading a Form from VBA
Hi all, I'd like a module to open and load a form in my Access 2003 database... How can I do this? Use the OpenForm method. Look in the Help file for details. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Mike" <michael.leon.schwartz@gmail.com> wrote in message news:1184770076.109526.207900@o11g2000prd.googlegroups.com... > Hi all, I'd like a module to open and load a form in my Access 2003 > database... How can I do this? > On Jul 18, 10:58 am, "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com&g...

Outlook client 07-11-03
I have installed the newest Outlook client for MS CRM yesterday and it was working pretty well. I logged off lastnight and when I logged on this morning the Outlook CRM ToolBar is no longer visible. Any ideas on how to reactivate this? ...

Can I use Word to merge with the addresses in Outlook Express?
I am trying to do my Christmas labels and want to know if I can use Outlook Express for the addresses. At work we have Outlook 2003 and it is a simple task to merge because you have different categories you can use. I need help please! Megabite wrote: > I am trying to do my Christmas labels and want to know if I can use > Outlook Express for the addresses. At work we have Outlook 2003 and > it is a simple task to merge because you have different categories > you can use. I need help please! No - you can only use mail merge with Outlook. You could export the address book...

Excel and VBA
I am very interested in learning more about using VBA in office, especially Excel. Can you post some resources (online, books, etc) that can be used to help learn about using Visual Basic in office. Thanks! Here's a good place to start: http://www.contextures.com/xlbooks.html Does that help? *********** Regards, Ron XL2002, WinXP "Bob Sinclair" wrote: > I am very interested in learning more about using VBA in office, especially > Excel. Can you post some resources (online, books, etc) that can be used to > help learn about using Visual Basic in office. >...

VBA Customization
Is there a way to get the name of the current company through VBA in Great Plains 8.0? Thanks for all your help. open GreatPlains. Add the current window, it will add the Toolbar then add fields choose the company name on the top left after the user id. >-----Original Message----- >Is there a way to get the name of the current company through VBA in Great >Plains 8.0? > >Thanks for all your help. > > > >. > Thanks. I tried, but I couldn't add company name to the field list. It opens up the login screen instead. Any thoughts? Thanks again. "ger...

Run VBA without show
I want excel to run the VBA code without showing me what it is doing. Which code should i use for that? Sub RunWithoutShow() Application.ScreenUpdating = False 'Paste the vba code here 'end of code 'Change screenupdating property to true Application.ScreenUpdating = True End Sub I hope this helps... Selva V Pasupathy For more on Excel, VBA, & other Resources Please visit: http://socko.wordpress.com You may also (inserting into quote from code example bellow from Socko) Use Application.Visible property to hide the application entirely Sub RunWithoutShow() Appli...

Form Controls vs VBA controls
I am new to VBA so just finding my feet, can anyone help me with th differences between an excel control (i.e. one from the form toolbox lets say a checkBox and a vba checkBox? From trying the two controls the I have noticed is that you canno capture the change event of the VBA checkbox in the code module, it ha to be done via the sheet (i.e. checkbox on sheet1, code goes in chang event on sheet1) the control is placed on, is this correct? What woul you do if you have three sheets with the same controls just differen data, do you really have to code the control 3 times? The excel control ho...

Word Gets Languages Confused
Word 2003, Windows XP Home Occasionally (about once every 50 =96 100 documents), the spell checker will flag a couple of words as misspelled. The words are spelled correctly. But it turns out that Word has, for some unknown reason, decided that it should test these words using the French (France) language. Thus, as an example, Word suggests as alternatives for the English word =93personal=94 the French words =93personne=94 or =93personale= =94 I've verified that the default language in Tools | language is English. It=92s not a real problem. But I'm a curious person ...

Referencing a ComboBox in VBA
Hi, I am using Excel 2007. I want to run some code in my Workbook_Open() Sub that fills a combo box on one of my Worksheets (I will call it myCombo on mySheet). I tried the following code and it did not work: myCombo.Clear myCombo.AddItem "Item One" myCombo.AddItem "Item Two" myCombo.AddItem "Item Three" I assume that the problem is that within the Workbook_Open() Sub, the reference to myCombo is not valid. Can anyone tell me if/how I can get a valid reference to myCombo (on mySheet)? Thanks in advance, Paul Kraemer -- Paul Krae...