I have this macro,
Sub exporttojournal()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim Rng As Word.Range
Dim i As Integer
Dim pathName As String
If MsgBox("Are you sure you want to export data as " & Range("AD9").Text & " ?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
pathName = Sheets("ADMIN SHEET").Range("A2").Value
Set wrdDoc = wrdApp.Documents.Open(pathName)
With Sheets("Calculator")
Set rngWord = .Range("U1:X1", .Range("U1:X1").End(xlDown))
End With
rngWord.Copy
Set Rng = wrdDoc.Range
Rng.Collapse 0 'wdCollapseEnd
Rng.PasteExcelTable False, True, False
With wrdDoc
.Content.InsertAfter "E1RM-"
With Sheets("Calculator")
Set rngWord = .Range("R1")
End With
rngWord.Copy
Set Rng = wrdDoc.Range
Rng.Collapse 0 'wdCollapseEnd
Rng.PasteAndFormat (wdFormatPlainText)
.Content.InsertParagraphAfter
.Content.InsertAfter "Total Volume-"
With Sheets("Calculator")
Set rngWord = .Range("R2")
End With
rngWord.Copy
Set Rng = wrdDoc.Range
Rng.Collapse 0 'wdCollapseEnd
Rng.PasteAndFormat (wdFormatPlainText)
.Content.InsertParagraphAfter
.Content.InsertAfter "Average Intensity-"
With Sheets("Calculator")
Set rngWord = .Range("R6")
End With
rngWord.Copy
Set Rng = wrdDoc.Range
Rng.Collapse 0 'wdCollapseEnd
Rng.PasteAndFormat (wdFormatPlainText)
End With
With wrdDoc
.SaveAs (pathName & "ADMIN SHEET!A2")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
With Sheets
Application.CutCopyMode = False
MsgBox "Data has been exported"
End With
End Sub
and am getting an error at this line, it says,
Run-time error'4198':
Method 'PasteAndFormat' of object 'Range' failed
Rng.PasteAndFormat (wdFormatPlainText)
This line is the 37th line down in the code.
What is the fix for this?
Bookmarks