error 5941 pulling bookmarks from excel into word

ozborn

New Member
Joined
Oct 10, 2016
Messages
6
so i finished this code on friday. ran perfect. came back on monday to rerun it, and now i have an error that pops up at
Code:
.Item("ARTextsalutation").Range.InsertAfter vARTextsalutation

It doesnt make sense to me why it would stop working for no reason.

Code:
Public Sub SendToWord()
      
    Dim wdDoc As Word.Document, objDoc As Word.Document, wdApp As Word.Application
    
    
    Dim vARTEXTaddress1 As Excel.Range, vARTextdate As Excel.Range, vARTextsalutation As Excel.Range
    Dim vARTextfirstname As Excel.Range, vARTextlastname_01 As Excel.Range, vARTextjobtitle As Excel.Range
    Dim vARTextaddress As Excel.Range
      
    Set wdApp = New Word.Application
     'Assign the Word file path and name to variables
       wdApp.Application.Templates.LoadBuildingBlocks
               
    FilePath = ThisWorkbook.Path
    FileName = "409a template 2.docx"
    Set objDoc = wdApp.Documents.Add(Template:=Application.ActiveWorkbook.Path & "\" & "409a template 2.docx")
    
    If objDoc Is Nothing Then
        MsgBox "Unable to find the Word file.", vbCritical, "File Not Found"
        wdApp.Quit
        Set appWrd = Nothing
        Exit Sub
    End If
    


Set vARTEXTaddress1 = Range("ARTEXTaddress1")
Set vARTextdate = Range("ARTextdate")
Set vARTextsalutation = Range("ARTextsalutation")
Set vARTextfirstname = Range("ARTextfirstname")
Set vARTextlastname_01 = Range("ARTextlastname")
Set vARTextjobtitle = Range("ARTextjobtitle")
Set vARTextaddress = Range("ARTEXTaddress")
Set vARTextcity = Range("ARTextcity")
Set vARTextstate = Range("ARTextstate")
Set vARTextzip = Range("ARTextzip")
Set vARTextvaluationdate = Range("ARTextvaluationdate")
Set vARTextproposalfee = Range("ARTextproposalfee")
Set vARTextdbfee = Range("ARTextdbfee")
Set vARTextretainerfee = Range("ARTextretainerfee")
Set vARTEXTvaluationdate_02 = Range("ARTEXTvaluationdate_02")
Set vARTEXTsalutation_02 = Range("ARTEXTsalutation_02")
Set vARTEXTfirstname_02 = Range("ARTEXTfirstname_02")
Set vARTextlastname_02 = Range("ARTextlastname_02")
Set vARTEXTjobtitle_02 = Range("ARTEXTjobtitle_02")
Set vARTEXTcompanyname_02 = Range("ARTEXTcompanyname_02")
Set vARTEXTretainerfee_02 = Range("ARTEXTretainerfee_02")
Set vARTEXTsalutation_03 = Range("ARTEXTsalutation_03")
Set vARTEXTlastname_03 = Range("ARTEXTlastname_03")
Set vARTEXTcompanyname_03 = Range("ARTEXTcompanyname_03")
Set vARTEXTcompanyname_04 = Range("ARTEXTcompanyname_04")
Set vARTEXTcompanyname_05 = Range("ARTEXTcompanyname_05")
Set vARTEXTcompanyname_06 = Range("ARTEXTcompanyname_06")
Set vARTEXTcompanyname_07 = Range("ARTEXTcompanyname_07")
Set vARTEXTcompanyname_08 = Range("ARTEXTcompanyname_08")


     
    With objDoc.Bookmarks
    
.Item("ARTEXTaddress1").Range.InsertAfter vARTEXTaddress1
        .Item("artextaddress1").Range = ""
                
.Item("ARTextdate").Range.InsertAfter vARTextdate
        .Item("ARTextdate").Range = ""
                      
.Item("ARTextsalutation").Range.InsertAfter vARTextsalutation
        .Item("ARTextsalutation").Range = ""
                
 .Item("ARTextfirstname").Range.InsertAfter vARTextfirstname
        .Item("ARTextfirstname").Range = ""
                
 .Item("ARTextlastname_01").Range.InsertAfter vARTextlastname_01
        .Item("ARTextlastname_01").Range = ""
                
 .Item("ARTextjobtitle").Range.InsertAfter vARTextjobtitle
        .Item("ARTextjobtitle").Range = ""
                
 .Item("ARTextaddress").Range.InsertAfter vARTextaddress
        .Item("ARTextaddress").Range = ""
                
 .Item("ARTextcity").Range.InsertAfter vARTextcity
        .Item("ARTextcity").Range = ""
                
 .Item("ARTextstate").Range.InsertAfter vARTextstate
        .Item("ARTextstate").Range = ""
                
 .Item("ARTextzip").Range.InsertAfter vARTextzip
        .Item("ARTextzip").Range = ""
                
 .Item("ARTextvaluationdate").Range.InsertAfter vARTextvaluationdate
        .Item("ARTextvaluationdate").Range = ""
                
 .Item("ARTextproposalfee").Range.InsertAfter vARTextproposalfee
        .Item("ARTextproposalfee").Range = ""
                
 .Item("ARTextdbfee").Range.InsertAfter vARTextdbfee
        .Item("ARTextdbfee").Range = ""
                
 .Item("ARTextretainerfee").Range.InsertAfter vARTextretainerfee
        .Item("ARTextretainerfee").Range = ""
                
  
.Item("ARTEXTsalutation_02").Range.InsertAfter vARTEXTsalutation_02
        .Item("ARTEXTsalutation_02").Range = ""
        
        
.Item("ARTEXTfirstname_02").Range.InsertAfter vARTEXTfirstname_02
        .Item("ARTEXTfirstname_02").Range = ""
                
 .Item("ARTextlastname_02").Range.InsertAfter vARTextlastname_02
        .Item("ARTextlastname_02").Range = ""
.Item("ARTEXTjobtitle_02").Range.InsertAfter vARTEXTjobtitle_02
        .Item("ARTEXTjobtitle_02").Range = ""


 .Item("ARTEXTcompanyname_02").Range.InsertAfter vARTEXTcompanyname_02
        .Item("ARTEXTcompanyname_02").Range = ""
        
 .Item("ARTEXTretainerfee_02").Range.InsertAfter vARTEXTretainerfee_02
        .Item("ARTEXTretainerfee_02").Range = ""
                
        
 .Item("ARTEXTsalutation_03").Range.InsertAfter vARTEXTsalutation_03
        .Item("ARTEXTsalutation_03").Range = ""
                
        
 .Item("ARTEXTlastname_03").Range.InsertAfter vARTEXTlastname_03
        .Item("ARTEXTlastname_03").Range = ""
                
        
 .Item("ARTEXTcompanyname_03").Range.InsertAfter vARTEXTcompanyname_03
        .Item("ARTEXTcompanyname_03").Range = ""
        
 .Item("ARTEXTcompanyname_04").Range.InsertAfter vARTEXTcompanyname_04
        .Item("ARTEXTcompanyname_04").Range = ""
                       
 .Item("ARTEXTcompanyname_05").Range.InsertAfter vARTEXTcompanyname_05
        .Item("ARTEXTcompanyname_05").Range = ""
        
 .Item("ARTEXTcompanyname_06").Range.InsertAfter vARTEXTcompanyname_06
        .Item("ARTEXTcompanyname_06").Range = ""
        
 .Item("ARTEXTcompanyname_07").Range.InsertAfter vARTEXTcompanyname_07
        .Item("ARTEXTcompanyname_07").Range = ""
        
 .Item("ARTEXTcompanyname_08").Range.InsertAfter vARTEXTcompanyname_08
        .Item("ARTEXTcompanyname_08").Range = ""
                
   
        
End With
        


     
     'Turn everything back on
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    Application.StatusBar = False
     'Let the user know the procedure is now complete
    Prompt = "Click OK to Review the Fruit Report Document in the Taskbar."
    Title = "Procedure Completion"
    MsgBox Prompt, vbOKOnly + vbInformation, Title
     'Make our Word session visible
    wdApp.Visible = True


     'Clean up
    Set wdApp = Nothing
    Set objDoc = Nothing
    
    'ErrorHandler:
'If Err.Number <> 0 Then
'    MsgBox Err.Number & "  " & Err.Description
'End If


    Set wdApp = Nothing
    Set objDoc = Nothing
     
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,195,950
Messages
6,012,487
Members
441,701
Latest member
vnkendijs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top