An Excel VBA file which able to open .dotm change it and save as an pdf for e-mail. Possible??

veyselk

New Member
Joined
May 22, 2018
Messages
1
Hi everyone I am trying to make a excel file with vba codes. Plan is that file save datas, choose information daily, open an existed word object (.dotm) change bookmarks I create and save it. All is fine till save as a .pdf and send e-mail via outlook app. I already do this in excel with active sheet but I want excel do this with a word file. Is there any examples like that to help me?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Here's some basic code to get you started:
Code:
Sub ExportToWord()
'Note: A reference to the Word library must be set, via Tools|References
Dim wApp As New Word.Application, wDoc As Word.Document
Dim xlwkBk As Workbook, xlSht As Worksheet
Dim sPath As String, sName As String
Set xlwkBk = ActiveWorkbook: Set xlSht = xlwkBk.ActiveSheet
'Set the save path to the workbook's folder and the save name to the value of A1 in the active sheet
sPath = xlwkBk.Path & "\": sName = xlSht.Range("$A$1").Value
With wApp
  .Visible = True
  'Create a new Word document from a suitable template
  Set wDoc = .Documents.Add(Template:="Template path & name", Visible:=True)
  xlSht.Range("$A$1:$J$10").Copy
  With wDoc
    'Paste some Excel data at the designated bookmark
    .Bookmarks("My Bookmark").Range.Paste
    ' Save & close the output document
    .SaveAs Filename:=sPath & sName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
    ' and/or:
    .SaveAs Filename:=sPath & sName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
    .Close SaveChanges:=False
  End With
End With
Set wDoc = Nothing: Set wApp = Nothing: Set xlSht = Nothing: Set xlwkBk = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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