Is it possible to import Word documents into Power Query?

olivierhbh

Board Regular
Joined
Jun 22, 2015
Messages
136
Hello all,

Do you know if there is a way to import word documents into Power Query?

I could save them as HTML and then import them but that would require a manual step for each of them so I'm looking for a different approach.

Thanks,
Olivier.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I don't believe this is possible without doing the manual step you mention. You could write some VBA to first convert the doc, but that would not be a trivial task.
 
Upvote 0
The VBA code to save a document in HTML format is indeed trivial:
Code:
Sub Demo()
With ActiveDocument
  .SaveAs FileName:=Split(.FullName, ".doc")(0) & ".htm", FileFormat:=wdFormatHTML, AddToRecentFiles:=False
End With
End Sub
As I don't use Power Query, though, I don't know what automation tools it provides such that it could both automate Word to open & convert the document, then open the resulting html file. If it give access to the standard Excel VBA model, even that isn't especially involved.
 
Last edited:
Upvote 0
Putting the vba in the word doc is trivial, but presumably more work than just saving the word file as html. Adding vba into the Excel workbook and making the process of selecting the required doc automaticly without adding an additional step (requirement in the op) is a lot more work.
 
Upvote 0
The corresponding Excel code, assuming a known filename, would be:
Code:
Dim wrdApp As New Word.Application, wrdDoc As Word.document, StrFlNm As String
StrFlNm = "C:\" & Environ("UserName") & "Documents\Some Document"
Set wrdDoc = wrdApp.Documents.Open(Filename:=StrFlNm & ".doc", AddToRecentFiles:=False)
With wrdDoc
  .SaveAs Filename:=StrFlNm & ".htm", FileFormat:=wdFormatHTML, AddToRecentFiles:=False
  .Close False
End With
wrdApp.Quit
Set wrdDoc = Nothing: Set wrdApp = Nothing
of course, you could also pass StrFlNm to the code as a parameter or have the user choose the file with a filepicker. None of this is exactly a challenging task.

You can then import the html file (StrFlNm & ".htm") into Power Query.

PS: Early binding assumed (i.e. an Excel VBA reference to Word is required).
 
Last edited:
Upvote 0
Hello,

Thanks for your answers, indeed maybe I could have a VBA script that would convert all files from a folder into Html files, I'll look into it and will let you know.

Thanks again!
Olivier.
 
Upvote 0

Forum statistics

Threads
1,224,138
Messages
6,176,586
Members
452,738
Latest member
kylua

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