VBA Copy Word (entire document) to Excel

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
780
Hello,

Trying to copy a word document to Excel, literally a data dump as a typical manual copy would do, the code I have so far is:

I am unsure how to adapt the strTemp bit to ensure to copy all across.

Many thanks in advance.

VBA Code:
Sub Copy_Raw_Data()

    '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:\Risk assessor\Data\PTI Risk Assessments\PTIReport (6).doc")
    '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
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,776
Hi James. My view is that XL cells can only contain 255 characters.... how can U fit a whole document in there? Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,129,372
Messages
5,635,880
Members
416,886
Latest member
coreyalaurence37

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
Top