Consulting

Results 1 to 2 of 2

Thread: Import data from Word to Excel - School Assignment

  1. #1
    VBAX Newbie
    Joined
    May 2015
    Posts
    2
    Location

    Lightbulb Import data from Word to Excel - School Assignment

    Hi,

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



    1. 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
      1. Heading 1 needs to be UPPERCASE
      2. Heading 2 and 3 need to be bold and underlined
      3. Paragraph is left as is
      4. Image is left as is
      5. Enumeration is put in a single row (cell)
      6. 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!

      Thanks,
      Ingvarr

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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"

    1. Use dialog box to get document
    2. Start Loop
    3. get first object
      1. Id Object typ
      2. Perform task according to Object type
        1. if Header then
          1. UPPERCASE
          2. Add Text to Cell
            1. Which Cell?


        2. elseIf Heading then
          1. Bold Underline

        3. Esleif Para Then
        4. Else If Footer then


    4. Loop Unitl End of Document
    5. Close Document
    6. Format worksheet
    7. Save Workbook
    8. Etc
    9. Etc
    10. Etc


    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.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •