Results 1 to 5 of 5

Thread: Error Night to Morning, pols answer quickly I'm in a pitch

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    2

    Error Night to Morning, pols answer quickly I'm in a pitch

    Hello I'm new, being honest I just join the forum for this issue, but whatever, the problem is the next.

    In the night, I got on the bed after finishing some documents with my macros, however, the next morning when my boss sent more work, and I was doing a new macro when I finished it gave me an error that error was the same as the last macro that I used last night, however, I solved that error without knowing how (I copy and pasted various thing till I achieved to eradicate the error), then now both the macro with the solved error which was working fine until now and the new macro with similar code simply threw me an error.

    Name:  troble.png
Views: 94
Size:  6.4 KB
    Name:  troble2.png
Views: 93
Size:  8.6 KB

    The first is the specific line where the trouble's shoot and the second is the error, no matter how much I search it I can find why it happens in VB, now I have like 3 hours to sent more than 300 documents, you can imagine that I wouldn't do it without a miracle, but if you see this after that time pls answer, it will help me in the future, thank you for reading

    Windows 10
    VSB 6

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,638

    Re: Error Night to Morning, pols answer quickly I'm in a pitch

    This looks like something for the Office forom. What code are you using?

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    2

    Re: Error Night to Morning, pols answer quickly I'm in a pitch

    Quote Originally Posted by Peter Swinkels View Post
    This looks like something for the Office forom. What code are you using?

    Code:
    Sub generar_word()
    
    ' Initializing template rute
    ruta = "C:\Users\Juan Jose\Desktop\Envios datos excel a word\Excel a word formatos\Template.docx"
    
    ' Creating saving rute
    Nombre = "2072234"
    MkDir "C:\Users\Work\Desktop\Envios datos excel a word\Excel a word formatos\Guardar2\" + Nombre
    
    ' Intializing word appication
    Dim objWord As Word.Application
    Set objWord = New Word.Application
    objWord.Visible = True
    
    ' Initializing For to check 25 values
    For j = 1 To 25
    ' Opening a new template to be reopen later when finished
        objWord.Documents.Add template:=ruta, NewTemplate:=False, DocumentType:=0
    
    ' Code line to move the control formulary
        Hoja1.Range("A" & 4).Value = j
       
    ' If which define if the program will enter to make the process of filling
        If Hoja2.Range("C" & "5") <> "RETIRO VOLUNTARIO" Then
    
    ' For to fill the template
            For i = 6 To 17
    
    ' Here it will search an especific word in the excel sheet to replace and will give to the variable remplazar the word which will replace
                buqueda = Hoja2.Range("D" & i).Text
                remplazar = Hoja2.Range("C" & i).Text
    
    ' Here will replace the word in busqueda with the word in replace
            With objWord.Selection.Find
                .Text = buqueda
                .Replacement.Text = remplazar
                .Execute Replace:=2
            End With
    
     
    
            Next i
    ' here the program will save the template once filled and then and then reapead the loop once again with a copy of the original template        
            objWord.ActiveDocument.SaveAs ("C:\Users\Work\Desktop\Envios datos excel a word\Excel a word formatos\Guardar2\" + Nombre + Hoja2.Range("C" & 6).Text + " " + Hoja2.Range("C" & 7).Text)
            End If
    Next j
    
    
    End Sub
    sorry most of it is in Spanish, since is my native language, I think it can be understood pretty well, just in case I put some commentaries

  4. #4
    Addicted Member
    Join Date
    Jan 2018
    Posts
    219

    Re: Error Night to Morning, pols answer quickly I'm in a pitch

    So you're trying to run Word from Excel? Can you launch Word manuallly? Maybe you accidentally dropped the Word reference from your project?

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,420

    Re: Error Night to Morning, pols answer quickly I'm in a pitch

    The error in English:
    80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))

    Maybe the referenced version of MS Word is not the same as the version on the computer?

    Early binding, as you now use:
    Code:
    Dim objWord As Word.Application
    Set objWord = New Word.Application
    Try late binding:
    Code:
    Dim objWord As Object
    Set objWord = CreateObject("Word.Application")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width