Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default trying to use PasteAndFormat method in Excel VBA is not working

I am having trouble pasting an Excel chart into Word. I am trying to use the
PasteAndFormat function, but no matter how I try to format it, I keep getting
errors. Does anyone know the correct way? I have added the Word control
libratry into my Excel VBA project. See the code below. I am using Office
2003 Professional Edition:

Public Sub CommandButton2_Click()
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlBook = Excel.ActiveWorkbook
Set xlSheet = xlBook.ActiveSheet

Dim appWord As Word.Application
Dim xlWordDoc As Word.Document
Dim wdRange As Range

Set appWord = CreateObject("Word.Application")

appWord.Application.Visible = True
Set xlWordDoc = appWord.Documents.Add
Dim CopyArea As Variant
Dim PrintRange As Variant
Dim PasteRange As Variant
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim a As Variant
Dim b As Variant
n = 1
For i = (4) To 217
If xlSheet.Cells(i, 4).Value = Cells(4, 4).Value Then
k = i
j = k + 2
a = xlSheet.Cells(j, 4).Value
b = xlSheet.Cells(4, 4).Value
Do While (a < b) And (j < 219)
j = j + 1
a = xlSheet.Cells(j, 4).Value
b = xlSheet.Cells(4, 4).Value
Loop
Set PrintRange = Range(Cells(k - 1, 4), Cells(j - 2, 11))
PrintRange.Select
Selection.Copy
Set PasteRange = xlWordDoc.Paragraphs(n).Range
xlWordDoc.Paragraphs(1).Range.PasteAndFormat Type:=wdChartPicture 'This is
the line that doesn't work
xlWordDoc.Paragraphs(1).Range.InsertBreak Type:=wdPageBreak
i = j - 1
n = n + 1
End If
Next i
End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenText method not working Pflugs Excel Programming 2 June 6th 06 01:21 AM
Help - PasteSpecial Method - Not Working ACase Excel Programming 1 November 1st 05 01:43 AM
Find Method Not Working Right ? Dan Thompson Excel Programming 11 November 4th 04 04:18 AM
Worksheet_Change method not working in Excel 97 Manoj Kumar Sharma Excel Programming 4 October 6th 04 10:38 AM
.Find method not working??? MDW Excel Programming 0 September 30th 04 01:23 PM


All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"