Jubinell
10-31-2007, 09:47 PM
Hi guys,
In one part of my subroutine, I need to copy a range of cells in Excel and then paste it in Word as unformatted text (so that a table is not created). The cells should replace a field that I created called "<log-in data>"
I have made use of the clipboard as follows:
Sub CopyCells()
Dim myRange as Range
Dim wrdApp as Word.Application
Dim wrdDoc as Word.Document
'....
myRange.Copy
With wrdApp.Selection
With .Find
.Text = "<log-in data>"
.Replacement.Text = ""
.Execute
End With
With .Selection
.PasteSpecial DataType:=wdPasteText
End With
End With
End Sub
However, this part of the subroutine has been giving me problems because from time to time I would get "Error: Clipboard cannot be emptied." I figured out that the error is coming from my usage of Remote Desktop while the macro is being run, but there's nothing I can do about it. I must have Remote Desktop open at this time.
My question is, is there a way rewrite this task without using the Clipboard?
Any help is greatly appreciated!
In one part of my subroutine, I need to copy a range of cells in Excel and then paste it in Word as unformatted text (so that a table is not created). The cells should replace a field that I created called "<log-in data>"
I have made use of the clipboard as follows:
Sub CopyCells()
Dim myRange as Range
Dim wrdApp as Word.Application
Dim wrdDoc as Word.Document
'....
myRange.Copy
With wrdApp.Selection
With .Find
.Text = "<log-in data>"
.Replacement.Text = ""
.Execute
End With
With .Selection
.PasteSpecial DataType:=wdPasteText
End With
End With
End Sub
However, this part of the subroutine has been giving me problems because from time to time I would get "Error: Clipboard cannot be emptied." I figured out that the error is coming from my usage of Remote Desktop while the macro is being run, but there's nothing I can do about it. I must have Remote Desktop open at this time.
My question is, is there a way rewrite this task without using the Clipboard?
Any help is greatly appreciated!