Ayuda con Macro Error con With - End With
Buena tarde a todos
Expertos, solicito de su apoyo con el siguiente código ya que cuando lo ejecuto me arroja el siguiente error "Error 91 en tiempo de ejecución Variable de objeto o bloque With no establecido" al momento de dar click en depurar me lleva a la siguiente linea" .GOtofield ("Body")" pero hay algunas veces que si permite enviarlo y o otras me arroja el error, según yo esta todo declaro y no debería de pasar este inconveniente.
Sub Lotus_VDS()
Dim NSession As Object
Dim NDatabase As Object
Dim NUIWorkSpace As Object
Dim NDoc As Object
Dim NUIdoc As Object
Dim WordApp As Object
Dim Subject As String
Dim HOY As Date
HOY = Hoja3.Range("D4").Value
Subject = "Ventanas de Servicio " & HOY
Debug.Print Subject
Set NSession = CreateObject("Notes.NotesSession")
Set NUIWorkSpace = CreateObject("Notes.NotesUIWorkspace")
Set NDatabase = NSession.GetDatabase("", "")
If Not NDatabase.IsOpen Then NDatabase.OPENMAIL
'Create a new Lotus Notes document
Set NDoc = NDatabase.CreateDocument
With NDoc
.SendTo = "[email protected]" 'CHANGE RECIPIENT EMAIL ADDRESS
.CopyTo = ""
.Subject = Subject
'Email body text, including marker text which will be replaced by the Excel cells
.Body = "Text in email body" & vbLf & vbLf & _
"B1:H42" & vbLf & vbLf & _
"Excel cells are shown above"
.Sabe True, False
End With
'Edit the just-created document to copy and paste the Excel cells into it via Word
Set NUIdoc = NUIWorkSpace.EDITDocument(True, NDoc)
With NUIdoc
'Find the marker text in the Body item
.GOtofield ("Body")
.FINDSTRING "B1:H42"
'.DESELECTALL 'Uncomment to leave the marker text in place (cells are inserted immediately before)
'Copy Excel cells to clipboard
Sheets("Detalle").Range("B1:H42").Copy 'CHANGE SHEET AND RANGE TO BE COPIED AND PASTED
'Create a temporary Word Document
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False 'True to aid debugging
WordApp.Documents.Add
'Paste into Word document and copy to clipboard
With WordApp.Selection
.PasteSpecial DataType:=4 'Enum WdPasteDataType: 10 = HTML; 2 = Text; 1 = RTF
.WholeStory
.Copy
End With
'Paste from clipboard (Word) to Lotus Notes document
.Paste
Application.CutCopyMode = False
WordApp.Quit SaveChanges:=False
Set WordApp = Nothing
.Send
.Close
End With
Set NSession = Nothing
Set WordApp = Nothing
End Sub
Agradeciendo su atención y ayuda
Saludos