Consulting

Results 1 to 9 of 9

Thread: Looking for Macro or VBA to edit word DOC

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Question Looking for Macro or VBA to edit word DOC

    Hello to all the GuRu's out there,
    What I have is a word doc full of test questions and I would like to run a macro or a VBA code to do what takes me hours to do. I have cut a part of the file that I am working with,

    Test Bank

    MULTIPLE CHOICE

    1. To assist in determining whether a patient seen in the ambulatory care setting has chronic insomnia, the nurse will initially
    a. schedule a polysomnography (PSG) study.
    b. arrange for the patient to have a sleep study.
    c. ask the patient to keep a 2-week sleep diary.
    d. teach the patient about the use of an actigraph.


    ANS: C
    The diagnosis of insomnia is made on the basis of subjective complaints and an evaluation of a 1- to 2-week sleep diary completed by the patient. Actigraphy and PSG studies/sleep studies may be used for determining specific sleep disorders, but are not necessary to make an initial insomnia diagnosis.

    DIF: Cognitive Level: Application REF: 116
    TOP: Nursing Process: Implementation MSC: NCLEX: Health Promotion and Maintenance

    2. Which instruction will the nurse include when teaching a patient with chronic insomnia about ways to improve sleep quality?
    a. Avoid aerobic exercise during the day.
    b. Read in bed for a few minutes each night.
    c. Keep the bedroom temperature slightly warm.
    d. Try to go to bed at the same time every evening.


    ANS: D
    A regular evening schedule is recommended to improve sleep time and quality. Aerobic exercise may improve sleep quality, but should occur at least 6 hours before bedtime. Reading in bed is discouraged for patients with insomnia. The bedroom temperature should be slightly cool.

    DIF: Cognitive Level: Application REF: 116
    TOP: Nursing Process: Implementation MSC: NCLEX: Physiological Integrity

    3. After the nurse has taught a patient about the use of extended-release zolpidem (Ambien CR) for insomnia, which patient statement indicates a need for further teaching?
    a. I will take the medication an hour before bedtime.
    b. I should take the medication on an empty stomach.
    c. I should not take this medication unless I can sleep for at least 6 hours.
    d. I will schedule activities that require mental alertness for later in the day.


    ANS: A
    Benzodiazepine receptor agonists such as zolpidem work quickly and should be taken immediately before bedtime. The other patient statements are correct.

    DIF: Cognitive Level: Application REF: 116 | 119 TOP: Nursing Process: Evaluation
    MSC: NCLEX: Physiological Integrity
    So, this is what I did,
    1) I copied a .rtf file into word without formatting and it looks like the above.
    2) what I would like to do is create something that will look for the question number "1" bring the question (everything up to the first multiple choice answer "A") then skip down to (ANS: C) , use this for reference to go back to the multiple choice answers and delete all but the correct answer. Then copy the paragraph directly after the "ANS: C". Then skip to the next question and do again until the end of file. This can be put in a new book or eliminate what is on the original. I am just wanting the output so when the question is read you get just the answer with explanation and do not fill your head with the incorrect items. I have put a sample of what I would like it to look like if possible.

    1. To assist in determining whether a patient seen in the ambulatory care setting has chronic insomnia, the nurse will initially
    c. ask the patient to keep a 2-week sleep diary.

    ANS: C
    The diagnosis of insomnia is made on the basis of subjective complaints and an evaluation of a 1- to 2-week sleep diary completed by the patient. Actigraphy and PSG studies/sleep studies may be used for determining specific sleep disorders, but are not necessary to make an initial insomnia diagnosis.


    2. Which instruction will the nurse include when teaching a patient with chronic insomnia about ways to improve sleep quality?

    d. Try to go to bed at the same time every evening.

    ANS: D
    A regular evening schedule is recommended to improve sleep time and quality. Aerobic exercise may improve sleep quality, but should occur at least 6 hours before bedtime. Reading in bed is discouraged for patients with insomnia. The bedroom temperature should be slightly cool.

    3. After the nurse has taught a patient about the use of extended-release zolpidem (Ambien CR) for insomnia, which patient statement indicates a need for further teaching?
    a. I will take the medication an hour before bedtime.

    ANS: A
    Benzodiazepine receptor agonists such as zolpidem work quickly and should be taken immediately before bedtime. The other patient statements are correct.

    I have a lot of books from school and have pulled answers and test banks to make these files and used then to study for my LPN boards and now I am back in school and will need to study for RN boards not to mention test throughout the next two years. My test bank should grow immensely and this will cut the info to just the pertinent info only. If anyone has the fix please feel free it will be greatly appreciated.Thank you very much
    John.

  2. #2
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    It would help to know a bit more about the formatting of the document.
    If you click on the Show\Hide () button, what do you see between at the end of each of the lines and between them where there is a space (e.g. before ANS:

  3. #3

    a copy of the full file.

    The original is an .rtf format file and I do not see any paragraph formatting. I can copy and paste all files to word and then deal with them as word opened them and it is easier. I have attached a file for you to look at. Hope this is enough to help figure it out. I have a bunch of these files as so I can open them all in word and then run macro or what ever you propose. Thank you again for your time.

    Attached Files Attached Files
    Last edited by jmendenhall2; 03-05-2013 at 07:52 AM. Reason: Figured out how to attach file

  4. #4
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    If you click on the Show\Hide () button, you would see the marks throughout the document that indicate the end of each paragraph.

    Based on the document that you attached, the following code will extract the required information which it will insert into a new document:

    Dim docSource As Document, docTarget As Document
    Dim rngAnswer As Range, rngQuestion As Range
    Dim strAnswer As String
    Dim strQuestion As Range
    Dim strReason As Range
    Dim i As Long, j As Long, k As Long
    Set docSource = ActiveDocument
    Set docTarget = Documents.Add
    With docTarget.Paragraphs(1)
    .LeftIndent = InchesToPoints(0.5)
    .FirstLineIndent = InchesToPoints(-0.5)
    End With
    With docSource
    For i = 1 To .Tables.Count
    Set rngQuestion = .Tables(i).Range
    rngQuestion.MoveStart wdParagraph, -1
    rngQuestion.MoveEnd wdParagraph, 4
    k = rngQuestion.Paragraphs.Count
    Set strQuestion = rngQuestion.Paragraphs(1).Range
    strQuestion.Start = strQuestion.Start + 1
    Set strReason = rngQuestion.Paragraphs(k).Range
    strReason.End = strReason.End - 1
    strAnswer = Mid(rngQuestion.Paragraphs(k - 1).Range.Text, 6, 1)
    j = Asc(strAnswer) - 64
    Set rngAnswer = rngQuestion.Tables(1).Cell(j, 2).Range
    rngAnswer.End = rngAnswer.End - 1
    With docTarget
    .Range.InsertAfter strQuestion
    .Range.InsertAfter Chr(Asc(strAnswer) + 32) & "." & vbTab & rngAnswer.Text & vbCr
    .Range.InsertAfter vbTab & strReason.Text & vbCr
    End With
    Next i
    End With

  5. #5
    Thank you Doug. I know how to add vba in excell but am not having any luck in word. I tried to add as template but when I finished I could not find it. Would it be to much to give directions on how to add into word. I have Mac word 14. Thank you.
    John

  6. #6
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    Hi John,

    See the article "What do I do with macrossent to me by other newsgroup readers to help me out?” at:

    http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm
    Sorry, I had not realised that you were using a Mac. As I developed the above on Windows computer, I hope that it works for you.

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    You posted an example of your input file, but I don't understand what you want to be output after the macro.
    If Chapter_001.doc is Before, could you post the desired After?

  8. #8
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    It's given in the text of the original post. Attached is a document created from Chapter_001.doc by the code that I posted.
    Attached Files Attached Files

  9. #9
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    I've been fiddling around with automating Word from Excel.
    (This is an MS Office forum.)
    I just noticed that you said your original file is in .rtf format.
    Is this a TextEdit file?

    AppleScript might be a better way than VBA.

    Could you attach the .rtf document?

Posting Permissions

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