Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2014, 07:26 AM
rsrasc rsrasc is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Competent Performer
Need Help With Another Macro-
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default Need Help With Another Macro-

I have two word documents. The first one is named "Questions" and the second one is named "Answers".



I would like to have a macro so I can import the information from the second file "Answers" to the first file named "Questions".

Both documents have the same numbers of questions and answers (55--but I would like to have it for an unlimited numbers of Q&As, if needed).

Here is a sample of one question in the first document.

1. Why macros are important?
a. A macro is a collection of commands.
b. Thy can automate almost anything.
c. Macros save time and expand the capabilities of the programs you use every day.
d. All of the above are correct.

Here is sample answer in the second document:

1. (d) The requirement is to identify the reason why macros in word document are important.



What I would like to see is the following output from the macro (the question follow by the answer choice after letter "d". The wording should read "Answer: D" (capital letter)- or any letter based on the answer choice showing for the same number in the second document):

1. Why macros are important?
a. A macro is a collection of commands.
b. Thy can automate almost anything.
c. Macros save time and expand the capabilities of the programs you use every day.
d. All of the above are correct.

Answer: D

1. (d) The requirement is to identify the reason why macros in word document are important.


Any ideas or suggestions are welcome.

As always your assistance is appreciated.

Let me know if more information is required.

Cheers
Reply With Quote
  #2  
Old 03-31-2014, 07:56 AM
fumei fumei is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Are you going to be doing this, or is this supposed to be some sort dynamic process? What I mean is, what CAUSES this process? Are you moving the content from Answers to Questions as a one-time thing? Making Questions into one document?
Reply With Quote
  #3  
Old 03-31-2014, 09:22 AM
rsrasc rsrasc is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Competent Performer
Need Help With Another Macro-
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Thank you for you question, and the answer are two. I have about 60 word documents containing only multiple choice questions (questions with the option a, b, c and d), and I have a different word file with the answer choices (together with the explanations).

If there is macro that could help me automate this--putting the questions, adding the answer choice, and the explanations--that will be great--kind of dynamic process.

Yes, I would like to move the content from the Answer file to the Question file, as a one thing, and maybe converting the Question file into one document.


If I can't get a macro, my choice will be to do it manually.

I hope this clarify your question.


PS. If there are any other options to accomplish this, I open for ideas/suggestions.

Thanks!
Reply With Quote
  #4  
Old 04-01-2014, 07:00 AM
Larry Sulky Larry Sulky is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Novice
 
Join Date: Mar 2014
Posts: 14
Larry Sulky is on a distinguished road
Default

rsrasc, I'm trying to private-mail you, but I'm not sure that it's working. Have you received anything from me?
Reply With Quote
  #5  
Old 04-01-2014, 07:12 AM
rsrasc rsrasc is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Competent Performer
Need Help With Another Macro-
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Hi Larry,

Yes, I received your private mail.

Thanks!
Reply With Quote
  #6  
Old 04-01-2014, 03:06 PM
macropod's Avatar
macropod macropod is offline Need Help With Another Macro- Windows 7 32bit Need Help With Another Macro- Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Larry Sulky View Post
rsrasc, I'm trying to private-mail you, but I'm not sure that it's working. Have you received anything from me?
Larry: Please keep forum-related discussions in the forum.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-03-2014, 04:19 PM
rsrasc rsrasc is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Competent Performer
Need Help With Another Macro-
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default Big Thank You Note to Larry Sulky

My kudos to Larry Sulky for the below code. I personally asked Larry for help and he responded to me with grace and attitude well beyond expectation.

The code was designed to group a series of questions (multiple choice questions) with their answers. My original intention was to put the questions and the answer choices and explanations in two different word documents so we could combined them together in one file.

With this in mind, Larry developed this amazing code to be used with just one file.

The intention was to have all the questions (the test file has 169 questions) listed all the way to the end of the file (questions with the a, b, c, and d option).

After all the questions were listed we add it all the answer explanations to all the questions, and the format of the answer explanation was as follow:

168. (a) The requirement is to identify the correct statement with respect to the primary orientation of operational auditing



Based on this, Larry Sulky, with his amazing code was able to come out with a solution to my request, and here is how the output looks now.

=================================================
168. Operational auditing is primarily oriented toward
a. Future improvements to accomplish the goals of management.
b. The accuracy of data reflected in management’s financial records.
c. The verification that a company’s financial statements are fairly presented.
d. Past protection provided by existing internal control.

Answer: A

168. (a) The requirement is to identify the correct statement with respect to the primary orientation of operational auditing

================================================== =
If the code is not listed in the appropriate format, please accept my apologies. Try to followed Macropod advise, but can't get to find it.

Cheers!

Code:
Sub CollateQandA() 
     ' Initialise common Find/Replace parameters.
    With Selection.Find 
        .ClearFormatting 
        .Replacement.ClearFormatting 
        .Format = False 
        .MatchCase = True 
        .MatchWholeWord = False 
        .MatchWildcards = True 
        .MatchSoundsLike = False 
        .MatchAllWordForms = False 
    End With 
     ' Ensure that there is a final dummy "question" by finding the first real answer
     ' and inserting a dummy there.
    Selection.HomeKey Unit:=wdStory 
    With Selection.Find 
        .Text = "[^013^l][0-9]@.[^s ]@[(][a-z]@[)]" 
        .Replacement.Text = "" 
        .Forward = True 
    End With 
    If Not Selection.Find.Execute Then Goto Finish 
    Selection.HomeKey Unit:=wdLine 
    Selection.TypeParagraph 
    Selection.TypeText ("0000. PLACEHOLDER QUESTION.") 
     ' Ensure that there is a final dummy "answer".
    Selection.EndKey Unit:=wdStory 
    Selection.TypeParagraph 
    Selection.TypeText ("0000. (z) PLACEHOLDER ANSWER.") 
     ' Ensure that there is a hard return before the first line of text.
    Selection.HomeKey Unit:=wdStory 
    Selection.TypeParagraph 
    Do 
        Dim myNumberStart As Integer 
        Dim myNumberStop As Integer 
        Dim myNumber As String 
        Dim myLetterStart As Integer 
        Dim myLetterStop As Integer 
        Dim myLetter As String 
         ' Hard returns and line breaks seem to be used interchangeably, so look for both.
         ' Also look for space or non-breaking space.
         ' Find the next correct answer.
        With Selection.Find 
            .Text = "[^013^l][0-9]@.[^s ]@[(][a-z]@[)]" 
            .Replacement.Text = "" 
            .Forward = True 
        End With 
        If Not Selection.Find.Execute Then Goto Finish 
         ' Get the number and letter of the answer.
        myNumberStart = 2 
        myNumberStop = InStr(1, Selection.Text, ".") 
        myLetterStart = InStr(1, Selection.Text, "(") + 1 
        myLetterStop = InStr(1, Selection.Text, ")") 
        myNumber = Mid(Selection.Text, myNumberStart, myNumberStop - myNumberStart) 
        myLetter = UCase(Mid(Selection.Text, myLetterStart, myLetterStop - myLetterStart)) 
         ' Get the whole answer and cut it.
        Selection.Collapse direction:=wdCollapseStart 
        With Selection.Find 
            .Text = "[!^013^l]@[^013^l]" 
            .Replacement.Text = "" 
            .Forward = True 
        End With 
        If Not Selection.Find.Execute Then Goto Finish 
        Selection.Cut 
         ' Find the matching question.
        With Selection.Find 
            .Text = "[^013^l]" & myNumber & "." 
            .Replacement.Text = "" 
            .Forward = False 
        End With 
        If Not Selection.Find.Execute Then 
             ' If no match, mark the answer as "UNMATCHED" and paste it at the bottom.
             'MsgBox "Missing question #" & myNumber & ".", , "Uh-oh"
            Selection.EndKey Unit:=wdStory 
            Selection.TypeParagraph 
            Selection.TypeText "UNMATCHED " 
            Selection.Paste 
            Selection.HomeKey Unit:=wdStory ' Go back to the top to find the next answer.
            Goto EndLoop ' Skip the rest of the loop processing, since we have no match.
        End If 
         ' Find the NEXT question, which marks the end of the CURRENT question.
        Selection.Collapse direction:=wdCollapseEnd 
        With Selection.Find 
            .Text = "[^013^l][0-9]@." 
            .Replacement.Text = "" 
            .Forward = True 
        End With 
        If Not Selection.Find.Execute Then Goto Finish 
         ' Insert the Answer marker and paste the actual answer.
        Selection.Collapse direction:=wdCollapseStart 
        Selection.MoveRight Unit:=wdCharacter, Count:=1 
        Selection.TypeText ("Answer: " & myLetter) 
        Selection.TypeText Text:=Chr(11) ' Insert a line break, since that seems to be preferred.
        Selection.TypeText "MATCHED " 
        Selection.Paste 
EndLoop: 
    Loop 
Finish: 
    Selection.HomeKey Unit:=wdStory 
     '''Selection.Delete Unit:=wdCharacter, Count:=1
    With Selection.Find 
        .Text = "[^013^l]MATCHED " 
        .Replacement.Text = "^l" 
        .Forward = True 
    End With 
    Selection.Find.Execute Replace:=wdReplaceAll 
    With Selection.Find 
        .Text = "0000. (z) PLACEHOLDER ANSWER." 
        .Replacement.Text = "" 
        .Forward = True 
        .MatchWildcards = False 
    End With 
    Selection.Find.Execute Replace:=wdReplaceAll 
    Selection.Delete Unit:=wdCharacter, Count:=1 
    With Selection.Find 
        .Text = "0000. PLACEHOLDER QUESTION." 
        .Replacement.Text = "" 
        .Forward = True 
        .MatchWildcards = False 
    End With 
    Selection.Find.Execute Replace:=wdReplaceAll 
     '''Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.HomeKey Unit:=wdStory 
Bye: ' Just for debug purposes.
End Sub

Last edited by macropod; 04-03-2014 at 05:34 PM. Reason: Added code tags & formatting
Reply With Quote
  #8  
Old 04-03-2014, 05:31 PM
macropod's Avatar
macropod macropod is offline Need Help With Another Macro- Windows 7 32bit Need Help With Another Macro- Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

rsrac: kindly read https://www.msofficeforums.com/faq.p...ontact_members

Quote:
Office questions should be posted on the forums, please do NOT ask for help with PM, email or visitor messages. Seeking help in the public forums has two main benefits:
  1. Anyone who might have a solution can contribute; and
  2. Others with similar problems can benefit from seeing how the problem can be solved.
Also, you have previously been asked to use the code tags when posting code. Please do so. They're on the 'Go Advanced' tab (as also previously advised).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 04-04-2014, 06:12 AM
Larry Sulky Larry Sulky is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Novice
 
Join Date: Mar 2014
Posts: 14
Larry Sulky is on a distinguished road
Default

Hi, Paul ---
I read the FAQ that you referenced but I'm not clear on one point of protocol: if two members are testing and debugging code, should every iteration of that code be posted here? I ask because some of the things that rsrasc and I were working through were small, silly glitches, so each iteration of the code was 99% the same as the previous one.
Cheers!
--- larry
Reply With Quote
  #10  
Old 04-04-2014, 06:26 AM
Larry Sulky Larry Sulky is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Novice
 
Join Date: Mar 2014
Posts: 14
Larry Sulky is on a distinguished road
Default Screen updating

rsrasc, Thanks for the kind words. There are optimisations that could be made that I didn't bother with, since your files are pretty small. One that I should have made, however, is to stop screen updating while the macro is running. The macro jumps around a lot, which takes screen refresh time. At the beginning of the macro, you could add:
Code:
Application.ScreenUpdating = False
and at the end:
Code:
Application.ScreenUpdating = True
Reply With Quote
  #11  
Old 04-04-2014, 06:41 AM
rsrasc rsrasc is offline Need Help With Another Macro- Windows 7 64bit Need Help With Another Macro- Office 2010 64bit
Competent Performer
Need Help With Another Macro-
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default Thanks Larry!

I will add the new code and will continue testing the macro. Out of 60 documents I'm down now to 27 more. What a great feeling!

Dear Macropod,

Please consider this thread closed and I would like to see the stamp "solved".

It is so nice to see it. Out of four (4) request, so far all of them have been resolved. Hummm, good score!

I'm hoping that any future request can be solved thru the forum so I don't have to damage my scoring average!.

The only reason I asked Larry for support it was because no one responded to my request. If this is a sin, I apologize for that.

I hope things will get better in the future.

Sincerely,

Roberto
Reply With Quote
  #12  
Old 04-04-2014, 02:25 PM
macropod's Avatar
macropod macropod is offline Need Help With Another Macro- Windows 7 32bit Need Help With Another Macro- Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Larry,

The question here really wasn't one of debugging code. Indeed, until post #7, where the final code was posted, there hadn't been any discussion of code. What had happened is that rsrasc had been asked a question, which had been answered.

The next we hear of - less than 24 hours later is that you two had taken the discussion off-line. That effectively means no-one else can contribute. I'm certainly not going to waste my time trying to work out a solution for a problem when I know that's happening and I doubt fumei or anyone else would either.

As it is, even though rsrasc is happy enough with it, the solution you came up with is quite inefficient. Had the code been discussed in the forum, we could have contributed to making it much more efficient...

rsrasc: re:
Quote:
I'm hoping that any future request can be solved thru the forum so I don't have to damage my scoring average!
It's not your score! After all, you're not the one doing the solving.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
custom icon, undo/redo for macro, permanent macro Rapier Excel 0 08-05-2013 06:30 AM
How do I assign a macro to a button when the macro is in my personal workbook? foolios Excel Programming 2 07-27-2011 02:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft