Consulting

Results 1 to 12 of 12

Thread: Solved: Macro - Q & A Prompting

  1. #1
    VBAX Regular
    Joined
    Jul 2012
    Posts
    10
    Location

    Solved: Macro - Q & A Prompting

    Hello everyone,

    I am become more familiar with writing code for macros and have done several templates for my place of work (we converted from wordperfect to word recently).

    This new template is causing me some grief - I cannot seem to wrap my head around what direction to go in.

    When the template is open, the user is provided a userform to enter some Data - (ie: Interviewer Name, Interviewee Name). When the user pressed OK, bookmarks on the template document are populated with various information provided by the user.

    The part I'm having trouble with is this: the body of the template is a transcription document that when complete would look something like this:

    Interviewer Name:<tab>Blah blah blah <carriage return by user>
    <empty line>
    Interviewee Name:<tab>Blah blah blah blah <carriage return by user>
    <empty line>
    Interview Name:<tab>Blah blah blah <carrige return by user>
    <empty line>
    Interviewee Name:<tab>Blah blah blah blah <carriage return by user>

    What I would like to have happen is:

    when the user pressed OK on the form, everything is populated and the template is ready to be typed in from the transcription recording with the Interview Name:<tab> already inserted into the document and the cursor at the ready for typing.

    THEN,

    when the user presses <ENTER> for a carriage return, I would like the <empty line> and Interviewee Name:<tab> to be automatically inserted into the document with cursor ready for typing.

    THEN,

    when the user presses <ENTER> for a carriage return, I would like the <empty Line> and Interviewer Name:<tab> to be inserted into the document, and so on...

    alternating between the Interviewee and Interviewer Name until the user is done transcribing the recording and exits out of the macro with the ESC key.

    Could you please give me some advice/guidance on how to execute this type of macro?

    Thank you very much in advance for your time,

    Leslie

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    There appears to be a bit of a conflict. You state:

    "userform to enter some Data - (ie: Interviewer Name, Interviewee Name). "

    So, for example, Interviewee Name is part of that data. And you state:

    "when the user pressed OK on the form, everything is populated"

    Which, one would assume, includes Interviewee Name.

    YET, you state:

    "when the user presses <ENTER> for a carriage return, I would like the <empty line> and Interviewee Name:<tab> to be automatically inserted"

    So, which is it? Everything, or something else.

    Also, you want ENTER to be used to add things (not that easy), but what if the text being typed needs an Enter??

  3. #3
    VBAX Regular
    Joined
    Jul 2012
    Posts
    10
    Location
    Let's see if I can clarify:

    When the template is opened, the user is first faced with a userform - and yes, this is where they will provide the Interviewer Name and Interviewee Name. Once the user has filled out the data on the userform (pops up as part of the macro when the template is first opened) and they press the OK command button, then these two names are used to populate two bookmarks that I have placed on the template:

    ie:

    Date: July 18, 2012
    Interviewer Name: [viewernamebookmark]SMITH
    Interviewee Name: [vieweenamebookmark]JONES
    -----

    What I then need to have happen is to have the Interviewer Name and Interviewee Name continue to be used throughout the template as the transcriptionist transcribes the audio recording. The end result of the transcription would look like this:

    Interviewer Name: Asks a question here <Carriage Return>

    Interviewee Name: Answers Question here <Carriage Return>

    Interviewer Name: Asks another question here <Carriage Return>

    Interviewee Name: Answers Here <Carriage Return>

    ------------

    What I am hoping to be able to do is everytime the transcriptionist pressed 'Enter", the next line is automatically populated with whatever the opposite is of the line that was just being typed on - ie: If they were typing the statement for the IntervieWER name, then when they press enter, the IntervieWEE name is automatically inserted at the start of the next row.

    The ONLY time the Enter key will ever be pressed in this document is when a new person talks on the recording.

    Does that make more sense?

    Thanks,
    Les

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    I wouldn't go the the trouble of remapping the enter key to run a macro. It is not easy and could really frustrate your user. Instead, couldn't you just train your user to use a unique keyboard shortcut to execute the code that places the alternating text? Here is one way to write the code:

    [VBA]Sub ScratchMacro()
    'A quick macro scratch pad created by Greg Maxey
    Dim oVars As Variables
    Dim oRng As Word.Range
    Set oRng = Selection.Range
    Set oVars = ActiveDocument.Variables
    'You would set these variables in your userform "OK" click event.
    oVars("Interviewer").Value = "Smith"
    oVars("Interviewee").Value = "Jones"

    On Error GoTo Err_Handler
    Err_ReEtry:
    Select Case oVars("WhoSpokeLast").Value
    Case " "
    'Don't know then default to interviewer
    oRng.Text = vbCr & oVars("Interviewer").Value & ": " & vbTab
    oVars("WhoSpokeLast").Value = oVars("Interviewer").Value
    oRng.Collapse wdCollapseEnd
    oRng.Select
    Case oVars("Interviewer").Value
    oRng.Text = vbCr & oVars("Interviewee") & ": " & vbTab
    oVars("WhoSpokeLast").Value = oVars("Interviewee")
    oRng.Collapse wdCollapseEnd
    oRng.Select
    Case oVars("Interviewee").Value
    oRng.Text = vbCr & oVars("Interviewer").Value & ": " & vbTab
    oVars("WhoSpokeLast").Value = oVars("Interviewer").Value
    oRng.Collapse wdCollapseEnd
    oRng.Select
    End Select
    Exit Sub
    Err_Handler:
    oVars("WhoSpokeLast").Value = " "
    Resume
    End Sub[/VBA]
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "I wouldn't go the the trouble of remapping the enter key to run a macro."

    Leslie, I would strongly agree with this. Using Enter as the vehicle is not a good idea.

    Please let us know if you have difficulty following the route Greg is suggesting.

  6. #6
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    I think there might be an easier way to set this up and remove the need for a macro at all. You're basically looking for a way to alternate questions and answers, and allow your typist to transcribe quickly.

    Why not set up two styles ("Question" and "Answer"), which have each other as the follow style.

    The template, then, would initially have the Question style be set up as a List style with a specific prefix, which you could have a macro change.

    Essentially, you would have
    Q[tab]text you type
    And then when you hit enter, the next line would be...
    A[tab]whatever text you type.

    I've attached a sample.

    If you didn't want to leave it as Q and A as the prefixes to this pseudo list template, then you could use the update macros I included, which basically are this:

    [vba]
    Sub UpdateQuestionStyle(sPrefix As String)
    With ActiveDocument
    .Styles("Question").ListTemplate.ListLevels(1).NumberFormat = sPrefix
    End With
    End Sub
    Sub UpdateAnswerStyle(sPrefix As String)
    With ActiveDocument
    .Styles("Answer").ListTemplate.ListLevels(1).NumberFormat = sPrefix
    End With
    End Sub
    [/vba]
    This was actually more simple prior to Word2010, since you could modify a "fake" list like this directly in the styles. But Word doesn't natively allow you to do this, although it's still available via VBA by using the code above.

    This is an alternate method to Greg's...
    Attached Files Attached Files

  7. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Alternate method to Greg's and better. I've attached a file that includes a userform for setting the style prefixes. To use as a template you should save as a template and change the AutoOpen procedure to an AutoNew.

    Nice suggestion Jason!!
    Attached Files Attached Files
    Last edited by gmaxey; 07-19-2012 at 12:30 PM. Reason: add attachment
    Greg

    Visit my website: http://gregmaxey.com

  8. #8
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Thanks for mocking that up better than I did, Greg. The only additional info for Leslie is that your transcribers (depending on the length of the question and/or answer) may want to break into pseudo paragraphs.

    This could be accomplished with the use of a manual line break (SHIFT+ENTER) without changing the style (which is how you get the initial text).

    Let us know how this goes, Leslie.

  9. #9
    VBAX Regular
    Joined
    Jul 2012
    Posts
    10
    Location
    Well it sounds like it would be exactly what I need - unforunately the firewall I'm behind at work won't allow me to download the macro files you've made up - so I will check them out when I go home tonight.

    Thanks so much for your time and efforts in helping me out with this! There will never be a time when the transcriber will need to break up a paragraph - just the nature of the type of statement they're working on...but I will keep the manual line break key strokes noted!

    I'll post a follow up when I have a chance to review the attachments this weekend...

    Thanks!!

  10. #10
    VBAX Regular
    Joined
    Jul 2012
    Posts
    10
    Location
    Without looking at the attachment, this question may already be answered - is there a way to have the Interviewer name and Interviewee Name input for the Q: and A: at the start of each paragraph? (the data taken from the userform the transcriber initially fills out)

  11. #11
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Short answer: yes.

    You can use the VBA code in my post to do it, assuming you have a style called "question" which is a numbered style.

  12. #12
    VBAX Regular
    Joined
    Jul 2012
    Posts
    10
    Location
    Wow again - you are an amazing group! Thank you once again for helping me out with this - it is exactly what I wanted with finesse!

    One further question and then we can mark this baby as 'Solved' - is there a way to macro the creation of the 'Question' and 'Answer' Quickstyles? I'm considering some of the end users of the template and they are going to be completely lost when it comes to creating the styles as needed.

    Thanks,
    Les

Posting Permissions

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