Open Embeded Word files and save them out

mmitchell

Registered User.
Local time
Today, 15:33
Joined
Jan 7, 2003
Messages
80
I am trying to do the following:

1. Loop through a table of embeded Word docs
2. Open each one
3. Save it as a file
4. Close the file
5. Loop to the next one

Here is my looping and opening code that is not working.

Code:
Dim rst As New ADODB.Recordset
Dim strTableName As String
Dim ctl As Control
    
strTableName = "T_EmbededDocs"

Set rst = CurrentDb.OpenRecordset(strTableName)

Do While Not rst.EOF
     Set ctl = rst.Fields("DocEmbeded") '.Value
     With ctl
        .Verb = acOLEVerbShow
        ' Activate object.
        .Action = acOLEActivate
     End With
    rst.MoveNext
Loop

I get an Object 424 required, then a type 13 mismatch.

My questions are these?
1. Is my loop correct?
2. Am I oepning the Word file correctly? Am I setting the control correctly?
3. Any ideas on how to save the file out passing the name to save?
 
I am getting closer. I could not find a way to open the embeded file without a form being open (still want to do it just in code and a recordset).

What I have now is a form with one button on it that runs this code. But it stops because it sayd there is no document open. I think I have to somehow set focus to the Word application but don't know how.
Code:
Dim ctl As Control
Dim strWordCaption As String

    
    Set ctl = Me!OLE_DocEmbeded

With ctl
         .Verb = acOLEVerbOpen
         .Action = acOLEActivate
End With

'Make sure that Word has the focus
Dim objWord As Word.Application     'Need to go to Tools->References->MS Word 8.0 Object and click it or you get compile error about it not being defiend.
            Dim SaveFile As String
             
            SaveFile = "c:\test.doc"    '**This is what we will save as
        
        MsgBox ActiveDocument.ActiveWindow.Caption  **This always says the name of the Access form with the button, needs to say Word I think***
        
            Set objWord = CreateObject("Word.Application")
                 With objWord
                                    .ActiveDocument.SaveAs SaveFile  'Saves File
                 End With

            'Release the object variable.
            Set objWord = Nothing
 
Here is the final way I exported my embeded docs. I could not find a way to make it completely automatic but had to put a button on a form and click on it for every record, but at least it was only one click.

I have attached the sample database (Access 2000) if you make any adjustments please report back here, thanks.

Thanks to all who helped.
 

Attachments

Dear mmitchell,

I just found your code listed at this Forum. I used it in my Access database and it works prefectly. However, I do have another question, how could we save more than one files into the embeded directory under one (same) ID? I am thinking about using a DO loop, but could not figure out the code to work.

Thanks SO much!
Mimi
 

Users who are viewing this thread

Back
Top Bottom