Need VBA Code to save as the word document in specific folder as given name in the spread sheet

srikanth605

New Member
Joined
Oct 23, 2013
Messages
11
Hi,

I have a code to copy the data from excel and paste into word document through book marks.

I am getting error to save the word document in specific folder with the given name in spread sheet.

Sub CopyRangeToWord()
Dim wd As Word.Application
Dim doc As Word.Document
Dim templ As String
Dim srcWkBkName As String
Dim srcWkBk As Workbook
Dim srcRg As String

srcWkBkName = "C:\BB & B\ BB & B SERVICES INC Template Revised.xls"
srcRg = "A1:I20"
Set wd = CreateObject("Word.Application")
wd.Visible = True
templ = "C:\BB & B\ BB & B Services Template.doc"
Set doc = wd.Documents.Add(Template:=templ)
Windows("BB & B SERVICES INC Template Revised.xls").Activate
Sheets("Data").Activate
With doc

doc.Bookmarks("Vendor_cost").Range.Text = Range("A2").Value
doc.Bookmarks("Customer_Number").Range.Text = Range("B2").Value
doc.Bookmarks("Address_Line1").Range.Text = Range("C2").Value
doc.Bookmarks("City_St_and_Zip").Range.Text = Range("D2").Value
doc.Bookmarks("Contact_Name").Range.Text = Range("E2").Value

doc.Bookmarks("Contact_Phone").Range.Text = Range("F2").Value
doc.Bookmarks("Contact_Email").Range.Text = Range("G2").Value

doc.Bookmarks("EMail_Address").Range.Text = Range("H2").Value

End With


ActiveDocument.SaveAs Filename:="C:\BB & B\" & Worksheets("Data").Range("I2").Value, _
FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False

End Sub

Please help me.

Thanks,
Sri
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,216,116
Messages
6,128,931
Members
449,480
Latest member
yesitisasport

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