How to Copy content from Word using VBA
As many of us want to deal with Microsoft Word Document from Excel Macro/VBA. I am going to write few articles about Word from Excel Macro. This is the first article which opens a Word Document and read the whole content of that Word Document and put it in the Active Worksheet in a particular Cell.
Opening an Word Document is more like Excel Workbook only.
To work the below code you need to Add the reference of Microsoft Word in your Excel Workbook.
Sub Copy_From_Word() Application.DisplayAlerts = False 'Disable all the Alerts from excel Application.ScreenUpdating = False 'After opening Word Doc, Document will not be visible 'Create a New Object for Microsoft Word Application Dim objWord As New Word.Application 'Create a New Word Document Object Dim objDoc As New Word.Document 'Open a Word Document and Set it to the newly created object above Set objDoc = objWord.documents.Open("C:\Users\Vish\Desktop\New Microsoft Office Word Document.docx") 'To Store all the content of that word Document in a variable strTemp = objDoc.Range(0, objDoc.Range.End) 'Now store that variable value in to a cell range Range("A1").Value = strTemp str1 = objDoc.Range(0, 1) Range("A2").Value = str1 Range("B2").Value = strTemp objDoc.Close SaveChanges:=wdDoNotSaveChanges objWord.Quit End Sub
My name is Vishwamitra Mishra. Friends Call me Vishwa. This blog is authored by me. I am an Excel Geek. Well, this blog talks a lot about my passion in Excels & Macros so I’ll not talk about it :) I am very much passionate about traveling & quite recently discovered that I am a good photographer too..:P
AND GET A FREE!
E-BOOK FOR EXCEL VBA BEGINNERS
DON'T MISS ANY NEW ARTICLE !
Get your FREE! E-Book & Have Every New Article Delivered Straight To Your Email-Box