PDA

View Full Version : Solved: Macro - Q & A Prompting



paella
07-18-2012, 11:19 AM
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

fumei
07-18-2012, 03:29 PM
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??

paella
07-18-2012, 04:05 PM
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

gmaxey
07-18-2012, 04:28 PM
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:

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

fumei
07-18-2012, 06:38 PM
"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.

Frosty
07-19-2012, 11:05 AM
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:


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

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...

gmaxey
07-19-2012, 12:15 PM
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!!

Frosty
07-19-2012, 01:13 PM
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.

paella
07-20-2012, 08:28 AM
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!!

paella
07-20-2012, 08:34 AM
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)

Frosty
07-20-2012, 08:58 AM
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.

paella
07-25-2012, 10:05 AM
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