paste to word

  • Thread starter Thread starter pmss
  • Start date Start date
P

pmss

hello
i did following macros for copying cell from sheet and paste on word
application, i have used checkbox also. it works properly. But i could not
used more than one checkboxes. i mean if i checked two checkboxes or more ,
it should copy two sheets or more as specified and paste on word as separate
pages for separate sheets.
Private Sub CommandButton1_Click()
Dim Objword As Object
Set Objword = CreateObject("word.Application")
Objword.Visible = True
If CheckBox1 = True Then
Sheets("summary unit rate").Range("A1:F45").Copy
Objword.Documents.Add
Objword.Selection.PasteSpecial
Application.CutCopyMode = False
Set Objword = Nothing
Else: Objword.Visible = False
End If

End Sub

help me to do this.

pmss
 
Hi

You can try using PageBreaks as shown below

Private Sub CommandButton1_Click()

Dim Objword As Object
Set Objword = CreateObject("word.Application")

Dim oDocument As Document

Objword.Visible = True

Set oDocument = Objword.Documents.Add

If CheckBox1 = True Then
Sheets("summary unit rate").Range("A1:F45").Copy
Selection.EndKey wdStory
Selection.Range.PasteSpecial
Selection.InsertBreak Type:=wdPageBreak
Application.CutCopyMode = False
End If

If CheckBox2 = True Then
Sheets("Sheet2").Range("A1:F45").Copy
Selection.EndKey wdStory
Selection.Range.PasteSpecial
Selection.InsertBreak Type:=wdPageBreak
Application.CutCopyMode = False
End If


Objword.Visible = False
Set Objword = Nothing

End Sub


Cheers
 
Hi

first error message occurs on the line :
message "users defined type not define"

then i have changed Document to Object, again error on
message "object doesnot support this property or method"

thanks

Pmss
 
Hi

Can you check if the Microsoft Word Library is added to references (Code
Window-->Tools--References)

Cheers
Shasur
 
Hi

Just i have checked the microsoft word Library , but still shows error on line

Selection.EndKey wdStory

Thanks
Pmss
 
Excel has its own Selection and MSWord has its own Selection.

You'll want to be specific which one you mean.

Objword.Selection.EndKey 6
or maybe
oDocument.Selection.EndKey 6
(You'll have to test. I don't speak MSWord from memory.)

Excel doesn't know what those constants (wdStory and wdPageBreak) are.

You can either add the reference or just make sure you "translate" them.

Open MSWord's VBE.
hit ctrl-g to see the immediate window
type:
?wdstory
and you'll see 6
type:
?wdPageBreak
and you'll see 7
 
Back
Top