• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel Data to Convert into Word.

Sarfraz

New Member
Dear Sir,

I am using excel 2007, can you please provide me a VBA code which will help me to convert my excel data into word file.
 
Try this code
Code:
Sub ExportToWord()
'Reference : Microsoft Word 12.0 Object Library
'----------------------------------------------
    Dim WdObj As Object, fName As String, Cell As Range

    fName = Sheets("Sheet1").[A1].Value
    If WorksheetFunction.CountBlank(Selection) = Selection.Cells.Count Then MsgBox "There Is No Data To Export", 64: Exit Sub
   
    Set WdObj = CreateObject("Word.Application")
    WdObj.Visible = False
    Selection.Copy                  'Your Copy Range
    WdObj.documents.Add
    WdObj.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
    Application.CutCopyMode = False

    If fName <> "" Then            'Make Sure fName Is Not Blank
        With WdObj
            .ChangeFileOpenDirectory "C:\Temp"    'Save Dir
            .ActiveDocument.SaveAs Filename:=fName & ".doc"
        End With
    Else
        MsgBox ("File Not Saved. Naming Range Was Botched, Guess Again.")
    End If

    With WdObj
        .ActiveDocument.Close
        .Quit
    End With

    Set WdObj = Nothing
End Sub
 
Back
Top