ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   can i convert my excel tab into a word document? (https://www.excelbanter.com/excel-worksheet-functions/161877-can-i-convert-my-excel-tab-into-word-document.html)

Enrique

can i convert my excel tab into a word document?
 
I want to take what I have in my worksheet and be able to export all of that
into a fomratted word file. I don't want to cut and paste. Is there a way to
export it to a word or html file. I want to program a button that says "click
here to generate report" then the reader will get a file that opens up in
Word or HTML. Any help is appreciated

Thanks.
ee

JW[_2_]

can i convert my excel tab into a word document?
 
This uses early binding, so you need to set a reference the the
Microsoft Word x.x Object Library. I can throw together a late binded
version if that is what you would prefer.
Sub CopyWorksheetToWord()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim ws As Worksheet
Application.ScreenUpdating = False
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
'edit to the range you want to copy
Set ws = ActiveSheet
ws.UsedRange.Copy
wdDoc.Paragraphs(wdDoc.Paragraphs.Count) _
.Range.InsertParagraphAfter
wdDoc.Paragraphs(wdDoc.Paragraphs.Count) _
.Range.Paste
Application.CutCopyMode = False
wdDoc.Paragraphs(wdDoc.Paragraphs.Count) _
.Range.InsertParagraphAfter
wdDoc.Content.InsertAfter ws.Name
Set ws = Nothing
With wdApp.ActiveWindow
If .View.SplitSpecial = wdPaneNone Then
.ActivePane.View.Type = wdNormalView
Else
.View.Type = wdNormalView
End If
End With
Set wdDoc = Nothing
wdApp.Visible = True
Set wdApp = Nothing
End Sub

Enrique wrote:
I want to take what I have in my worksheet and be able to export all of that
into a fomratted word file. I don't want to cut and paste. Is there a way to
export it to a word or html file. I want to program a button that says "click
here to generate report" then the reader will get a file that opens up in
Word or HTML. Any help is appreciated

Thanks.
ee




All times are GMT +1. The time now is 07:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com