2013-06-26 21 views
6

Sto cercando di salvare i documenti di Word usando Excel VBA, ma ottengo l'errore "Il componente ActiveX non può creare oggetti".Errore di run-time '429': il componente ActiveX non può creare oggetti VBA

Quando eseguo il debug, l'errore viene dalla riga: Set wrdApps = CreateObject("Word.Application"). Stava funzionando bene, ma poi ha appena iniziato a darmi questo errore. Qualcuno sa come risolvere questo problema? Grazie per l'aiuto!

Sub saveDoc() 

Dim i As Integer 
For i = 1 To 2661: 
    Dim fname As String 
    Dim fpath As String 

    With Application 
     .DisplayAlerts = False 
     .ScreenUpdating = False 
     .EnableEvents = False 
    End With 

    fname = ThisWorkbook.Worksheets(3).Range("H" & i).Value 
    fpath = ThisWorkbook.Worksheets(3).Range("G" & i).Value 

    Dim wrdApps As Object 
    Dim wrdDoc As Object 

    Set wrdApps = CreateObject("Word.Application") 

    'the next line copies the active document- the ActiveDocument.FullName 
    ' is important otherwise it will just create a blank document 
    wrdApps.documents.Add wrdDoc.FullName 

    Set wrdDoc = wrdApps.documents.Open(ThisWorkbook.Worksheets(3).Range("f" & i).Value) 
    ' do not need the Activate, it will be Activate 
    wrdApps.Visible = False 

    ' the next line saves the copy to your location and name 
    wrdDoc.SaveAs "I:\Yun\RTEMP DOC & PDF\" & fname 

    'next line closes the copy leaving you with the original document 
    wrdDoc.Close 

    On Error GoTo NextSheet: 
NextSheet: 
    Resume NextSheet2 
NextSheet2: 
Next i 

With Application 
    .DisplayAlerts = True 
    .ScreenUpdating = True 
    .EnableEvents = True 
End With 

End Sub 
+0

** [Questo post] (http://www.ozgrid.com/forum/showthread.php?t=50936) ** su OzGrid può aiutare. L'unica differenza che ho visto da ciò che hai è che wrd.Apps sarebbe stato impostato come Word.Application e wrd.Doc sarebbe stato impostato come Word.Document. – chuff

+0

prova ad eseguire una riparazione su Office, e riavvia il pc ... il codice che hai 'CreateObject (" Word.Application ")' dovrebbe funzionare bene –

+0

se l'oggetto che stai cercando di "ottenere" ha privilegi elevati. restituirà l'errore 429 - non aprire come amministratore – Hightower

risposta

0

wrdDoc è inizializzato? Stai cercando di usare wrdDoc prima che l'oggetto sia stato impostato?

wrdApps.documents.Add wrdDoc.FullName 
Set wrdDoc = wrdApps.documents.Open(ThisWorkbook.Worksheets(3).Range("f" & i).Value) 

caso in cui la prima linea essere ActiveDocument.FullName come nei commenti? Quindi:

wrdApps.documents.Add ActiveDocument.FullName 
0

Verificare che avete la Libreria oggetti di Microsoft Excel e la libreria di oggetti di Microsoft Office spuntato in Strumenti> Riferimenti e che sono state registrate.

Se sono spuntati, potrebbe essere necessario eseguire Rileva problemi e ripristina dal menu Guida di Excel per assicurarsi che l'installazione di Office non sia danneggiata in alcun modo.