View Full Version : Import data from Word to Excel - School Assignment

05-11-2015, 01:08 PM

I am new on this forum and a beginner in VBA. I have a school assignment:

Create a VBA macro to parse the provided sample Word document (.docx format) by following this set of rules:

Output of the VBA macro is an Excel document (.xlsx format)
Each type of Word object found in document (paragraph, heading, image etc) will be placed in Column A in the next available row in sheet1, according to the order in the Word document

Heading 1 needs to be UPPERCASE
Heading 2 and 3 need to be bold and underlined
Paragraph is left as is
Image is left as is
Enumeration is put in a single row (cell)
Table: values of column “req” and “content” should be put in the cell in format “req => content”

If there is a header, the macro will put a tag “<header>” in cell A1, and similar for footer, in last A cell.
Empty lines (paragraphs) will not be put in Excel document as empty rows
Code should have enough comments (in English) to be understandable to normal user

Any help you can give me would be greatly appreciated!


05-11-2015, 09:11 PM
The first question is, "Is the macro going to be in a Word Document or in an Excel Workbook?

That is a pretty advanced assignment for a beginner. Depending on the chosen programming style, I can see from 1 to several dozen procedures and functions stored in up to half a dozen modules.

Obviously, your instructor does not think that you are the VBA Beginner you say you are. Is your major expertise in VBA for Word, or VBA for Excel. Mine is in VBA for Excel, ( My Word VBA = 0,) but we have experts in both.

We don't "do" homework but we love to help you thru the pain. The first thing you need to develop is a rough flow chart/list/algorythm

For example, using Excel "macros"

Use dialog box to get document
Start Loop
get first object

Id Object typ
Perform task according to Object type

if Header then

Add Text to Cell

Which Cell?

elseIf Heading then

Bold Underline

Esleif Para Then
Else If Footer then

Loop Unitl End of Document
Close Document
Format worksheet
Save Workbook

Make it as complete and detailed as you can imagine.

Remember I said that there could be numerous "Macros" and Functions? Imagine each line in that rough outline as a different concise and precise little macro with a master that calls them as needed. Obviously some, Like AddTextToCell will be reused.