copy excel to word

  • Thread starter lovepeaceofmind
  • Start date
L

lovepeaceofmind

Hi, everybody:

I never did this before and I need your expertise. I would like to
create a macro button in excel such that whenever I click this button,
3 columns (A, B, and C) with unknown rows under excel sheet1 will be
copied and pasted as Unformatted Text into an automatically created
word document. Three requirements:
1) The automatically created word document will have a left and
right margin of 0.6";
2) Any rows with something in column A in Excel will be shown as
Bold Text in the word documet after copy and copy;
3) The first line of the word document will be center aligned.
Anything else will be justified.

I appreciate any of your help. You all have a nice 4th of July.

Jorge
 
L

lovepeaceofmind

Hi, John and JL:

I tried what you said but still no luck. Any other ideas?

Thanks,

Jorge
 
G

George

Hi, Jorge:

Since I did not see many MVP level expertises showing up today, I did
a search and find something from our previous post + my own pratice.
Due to my shortage of knowledge, the following code is only for your
reference (copy 3 columns from excel and paste special as unformatted
text into word) as it doesn't solve your problem. You will need to
make a word template with left and right margins of 0.6" and save it
under C:\ drive. You will also need to make a bookmark to specify
where you want to paste in this word template. I really wish many
people will get into this as this is really common in reality. Correct
me if I did anything wrong. Thanks,

Sub Test()

Const wdGoToBookmark = -1
Const wdSaveChanges = -1
Dim ws As Worksheet
Dim i As Integer
Dim WdApp As Object
Dim strFile As String
Dim doc As Object

'I assume column C has the most rows among A, B, and C
Set Rng = Sheets("Sheet1").Range(Cells(1, "A"), Cells(Rows.Count,
"C").End(xlUp))

Rng.Select
Selection.Copy

strFile = "C:\CopyExcelToWord.doc"
On Error Resume Next
Set WdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set WdApp = CreateObject("Word.Application")
End If


WdApp.Documents.Open Filename:=strFile, ConfirmConversions:=False,
ReadOnly:=False
Set doc = WdApp.activedocument
WdApp.Visible = True

With WdApp
.Selection.GoTo What:=wdGoToBookmark, Name:="bkmk"
.Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:=wdInLine, DisplayAsIcon:=False
End With

Set WdApp = Nothing

End Sub
 
J

John

What happend when you recorded yourself doing it? What shoed up in the
macro?

John
 
L

lovepeaceofmind

Hi, George:

I just had a chance to be online. Thanks for all the work you did. I
will try what you wrote here. Thanks again!

Jorge
 
L

lovepeaceofmind

Hi, George:

I tried but not sure what's the meaning of
Const wdGoToBookmark = -1 and
Set WdApp = Nothing

Also, how to make a bookmark?

Thanks,

Jorge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top