I have a macro which uses a data from an excel file and auto populates a Word document (template). The macro copies text from certain cells and pastes them in the Word document at bookmark locations. However, some times Error code 4605 'This method or property is not available because the Clipboard is empty or not valid'. It almost seems random in where the error appears in the code. In addition I am having trouble with the Word app staying 'live' when the macro runs into an error and I cant seem to close it. This may have something to do we me using objWord and not appWord. But when I substitute objWord for appWord in the code below, it cant seem to find the bookmarks.
Any help with why the error is showing and how to fix it and then how to fix this terminating appWord issue.
![]()
Sub LeaseIndividual() Dim objWord As Object Dim uname Set objWord = CreateObject("Word.Application") uname = Range("H4").Value objWord.Documents.Open "C:\Users\LARKIN\Desktop\Lingley House\Templates\Lease_Individual.docx" objWord.Selection.Goto What:=wdGoToBookmark, Name:="TENANT" ActiveSheet.Select Range("H5").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="TENANT1" ActiveSheet.Select Range("H5").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="RENT" ActiveSheet.Select Range("D7").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="ROOM" ActiveSheet.Select Range("D4").Copy objWord.Selection.PasteSpecial DataType:=wdPasteTextl objWord.Selection.Goto What:=wdGoToBookmark, Name:="ROOM1" ActiveSheet.Select Range("D4").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="CARPARKING" ActiveSheet.Select Range("H15").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="START" ActiveSheet.Select Range("H16").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="END" ActiveSheet.Select Range("H17").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="COMPANY" ActiveSheet.Select Range("H4").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="COMPANY1" ActiveSheet.Select Range("H4").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="COMPANY2" ActiveSheet.Select Range("H4").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="ADDRESS1" ActiveSheet.Select Range("H9").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="ADDRESS2" ActiveSheet.Select Range("H10").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="ADDRESS3" ActiveSheet.Select Range("H11").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.Goto What:=wdGoToBookmark, Name:="ADDRESS4" ActiveSheet.Select Range("H12").Copy objWord.Selection.PasteSpecial DataType:=wdPasteText objWord.Selection.WholeStory objWord.Selection.Copy objWord.ActiveDocument.SaveAs Filename:="C:\Users\LARKIN\Desktop\Lingley House\" & uname & "\Lease\ " & uname & " " & _ Format(Date, "yyyy-mm-dd") & "-Lease.docx", FileFormat:= _ wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _ :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _ :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False objWord.Selection.Paste objWord.Selection.Font.ColorIndex = wdAuto objWord.Visible = True objWord.ActiveDocument.SaveAs Filename:="C:\Users\LARKIN\Desktop\Lingley House\" & uname & "\Lease\ " & uname & " " & _ Format(Date, "yyyy-mm-dd") & "-Lease.pdf", FileFormat:= _ wdFormatPDF objWord.Quit Set objWord = Nothing End Sub
Thanks











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks