Excel to Word Macro Help!

eddy

Well-known Member
Joined
Mar 2, 2002
Messages
521
I am using the macro below to copy the contents of a spreadsheet and then automatically
produce a Word document with a filename determined by :-

StrFileName = "X:\Quotes\WordEducationalQuotes\" & Replace(Sheets("CopySheet").Range("B2"), " ", "") & ".doc"

What I would like to do is first open a word template (x:\Quotes\MasterQuoteTemplate.doc), then past the contents into the template, then save it with a filename determined by :- StrFileName = "X:\Quotes\WordEducationalQuotes\" & Replace(Sheets("CopySheet").Range("B2"), " ", "") & ".doc"


Could someone help me with the coding to achieve this please.

Many Thanks Ed



Sub Copy2Word()
Dim appWD As Word.Application
Dim StrFileName As String


StrFileName = "X:\Quotes\WordEducationalQuotes\" & Replace(Sheets("CopySheet").Range("B2"), " ", "") & ".doc"

Set appWD = CreateObject("Word.Application")
appWD.Visible = True
appWD.Documents.Add

Sheets("CopySheet").Range("B2:G48").Copy

appWD.Selection.PasteExcelTable False, False, True

With appWD.Selection.ParagraphFormat
.LeftIndent = appWD.CentimetersToPoints(-2.54)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
appWD.Selection.PageSetup.LeftMargin = CentimetersToPoints(0.95)

appWD.ActiveDocument.SaveAs Filename:=StrFileName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False


End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi eddy,

Have you tried inplace of

appWD.Documents.Add

try

appWD.Documents.Open Filename:="x:\Quotes\MasterQuoteTemplate.doc"

ColinKJ
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top