Stuffing autocorrect entries separated by tabs into clipboard in Word 2003

A

Alan

Here's what I want to do:
I am working in Word 2003, transcribing medical dictation. I receive a
document into which I transcribe the dictation. There are several data in
the supplied demographic sheet: A medical record number, a first name, and a
last name. Thanks to help from this group, I constructed a macro that
creates an autocorrect entry for each of these data.

I want to create a macro that will put these three data, separated by tabs,
into the clipboard buffer. That way, I can switch to a spreadsheet and paste
these three data into three adjacent cells and switch back to Word.

I could just type them out onto the page, highlight, and block them and
maybe even figure out a way to record such a process as a macro. But is
there a way to do this on-the-fly without having to type the data, or even
have a macro type the data, into the document?
 
G

Graham Mayor

How do the three items appear in the document?
Can you display an example?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alan

The document is divided into a header, a text area, and a footer with a page
break. I am able to get the three items into three separate autocorrect
entries. That way, instead of having to type out the patient's name half a
dozen times, I can use the autocorrect entry so that typing UU (for first
name) and PP (for last name) expands out into Ignatze
Kadiddlehopper-VonStuppen (sorry, but it's late and I'm tired).

Anyhow, I've already got the macro written that creates an autocorrect entry
for the medical record number (MRN), first name (UU), and last name (PP).
These have been very useful over the past several days.

But I also enter these data into a spreadsheet. One way of quickly doing
that is to type out the following on a separate line:
MRN <then tab> PP <then tab>UU <then tab>
This results in
999988.....Kadiddlehopper-VonStuppen......Ignatz (where the spaces between
these are actually tabs).

Then I can highlight these, hit <alt><x> to cut to the clipboard, hit
<alt><shift> to switch to the spreadsheet, place the cursor into the medical
record cell, and hit <ctrl><v>, which pastes the whole shmeer into three
adjacent cells.

What I hope to be able to do is to write a macro that will look into the
silicone memory banks, find MRN, PP, UU, and then stuff the values into
which they expand into the clipboard, separated of course by tabs.

Is that possible?

Regards,

Alan
 
D

Doug Robbins - Word MVP

I think that you should really be doing something more like that covered in
the last of these articles:

Please Fill Out This Form
Part 1: Create professional looking forms in Word
http://www.computorcompanion.com/LPMArticle.asp?ID=22

Part 2: Adding Automation to your Word forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=46

Part 3: Learn more VBA (macros) to automate your forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=119

Part 4: Use custom dialog boxes in your Word forms
http://www.computorcompanion.com/LPMArticle.asp?ID=127

Part 5: Connect your AutoForm to a database to save input time and keep
better records!
http://www.computorcompanion.com/LPMArticle.asp?ID=136


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Summer

Do you know that Autocorrect is also in Excel which I am assuming is your
spreadsheet - so you already have your expansion available (I use some 1850
entries) Does that help!
 
A

Alan

Thanks for the input, Doug.

Those are interesting but not what I need.

I have to work in a very narrowly-defined set of parameters that are set for
me. What I need to be able to do is figure out how I can stuff three
autocorrect expansions, separated by tabs, into the clipboard. I can do it
using an AutoHotKey script, but I would rather have a VBA macro that does
it.

So forms are not what I need. What I need is to be able to cause the
clipboard to be filled with three autocorrect expansions separated by two
tabs.

Regards,

Alan
 
A

Alan

Hi Summer,

With all due respect, that's not what I need. This is what I need, bearing
in mind that I don't know very much about VBA

Dim aTmp as string
Dim bTmp as string
Dim cTmp as string
aTmp:=Autocorrect(UU) 'assign contents of autocorrect entry UU to aTmp
(patient's last name)
bTmp:=Autocorrect(PP) 'assign contents of autocorrect entry PP to bTmp
(patient's first name)
cTmp:+Autocorrect(MRN 'assign contents of autocorrect entry MRN to CTmp
(medical record number)
clipboard:=aTmp + CHR(9) bTmp + CHR(9) + cTmp 'concatonate the patient's
last name, tab, pt first name, tab, MRN into keyboard

That's what I need to be able to do. I assume VBA can do it. But how?

Regards,

Alan
 
S

Summer

Due respect also what you propose will not work.

Alan said:
Hi Summer,

With all due respect, that's not what I need. This is what I need, bearing
in mind that I don't know very much about VBA

Dim aTmp as string
Dim bTmp as string
Dim cTmp as string
aTmp:=Autocorrect(UU) 'assign contents of autocorrect entry UU to aTmp
(patient's last name)
bTmp:=Autocorrect(PP) 'assign contents of autocorrect entry PP to bTmp
(patient's first name)
cTmp:+Autocorrect(MRN 'assign contents of autocorrect entry MRN to CTmp
(medical record number)
clipboard:=aTmp + CHR(9) bTmp + CHR(9) + cTmp 'concatonate the patient's
last name, tab, pt first name, tab, MRN into keyboard

That's what I need to be able to do. I assume VBA can do it. But how?

Regards,

Alan
 
T

Tony Jollans

I'm not entirely clear what you are trying to achieve or whether this is the
best way of going about it, but this should be the syntax to do what you ask
...

Dim aTmp as string
Dim bTmp as string
Dim cTmp as string
aTmp = Application.AutoCorrect.Entries("UU").Value
bTmp = Application.AutoCorrect.Entries("PP").Value
cTmp = Application.AutoCorrect.Entries("MRN").Value
With New DataObject
.SetText aTmp & vbtab & bTmp & cTmp, 1
.PutInClipboard
End With

You will need a reference to the "Microsoft Forms 2.0 Object Library" - the
easiest way might be just to add a blank userform to the project and it
automatically be set.
 
S

Summer

Without going into reasons - and I am sure someone will be able to improve
on this macro (with due respect) but it does do what you asked for except
using autotext entries.


Using Autotext Entries currently saved in Normal.dot (or any template you
choose and name in macro), just resave your autocorrect entries as autotext
assigned to same template which you name in macro. The speed is identical to
autocorrect with due respect.



Press F3 to play (insert) a named autotext entry when typing. You also have
option to have richtext with autotext.





Autotext entries are named for this test macro:



z1 LastName

z2 FirstName

z3 MRN





Option Explicit



Sub GlobalAT1()

Dim aTemplate As Template

Dim myTemplate As Template

For Each aTemplate In Templates

If aTemplate = "Normal.dot" Then

Set myTemplate = aTemplate

myTemplate.AutoTextEntries("z1"). _

Insert Where:=Selection.Range, RichText:=True

Selection.TypeText Text:=vbTab



myTemplate.AutoTextEntries("z2"). _

Insert Where:=Selection.Range, RichText:=True

Selection.TypeText Text:=vbTab



myTemplate.AutoTextEntries("z3"). _

Insert Where:=Selection.Range, RichText:=True





Exit For

End If

Next



Selection.HomeKey Unit:=wdLine

Selection.EndKey Unit:=wdLine, Extend:=wdExtend

Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

Selection.Copy



End Sub



Summer

www.docsliveonline.com
 
S

Summer

Very nice!
Tony Jollans said:
I'm not entirely clear what you are trying to achieve or whether this is
the best way of going about it, but this should be the syntax to do what
you ask ..

Dim aTmp as string
Dim bTmp as string
Dim cTmp as string
aTmp = Application.AutoCorrect.Entries("UU").Value
bTmp = Application.AutoCorrect.Entries("PP").Value
cTmp = Application.AutoCorrect.Entries("MRN").Value
With New DataObject
.SetText aTmp & vbtab & bTmp & cTmp, 1
.PutInClipboard
End With

You will need a reference to the "Microsoft Forms 2.0 Object Library" -
the easiest way might be just to add a blank userform to the project and
it automatically be set.
 
S

Summer

Tony, I get an error:

User defined type not defined at NewDataObject

how do I fix that?
 
T

Tony Jollans

What do you mean by 'play'? All it does it put it in the clipboard for
manual pasting.
 
S

Summer

Yes, I see that now Tony (it's late). Mine pales in comparison (but I
learned a lot) thank you!
 
G

Graham Mayor

To do what you ask literally -

Dim AC As AutoCorrectEntry
Dim sAC1 As String
Dim sAC2 As String
Dim sAC3 As String
Dim dEXCEL As DataObject
With Application
For Each AC In .Autocorrect.Entries
With AC
If .Name = "MRN" Then
sAC1 = .Value
End If
If .Name = "PP" Then
sAC2 = .Value
End If
If .Name = "UU" Then
sAC3 = .Value
End If
End With
Next AC
Set dEXCEL = New DataObject
dEXCEL.SetText sAC3 & vbTab & sAC2 & vbTab & sAC1
dEXCEL.PutInClipboard
End With

However it should be possible to fire up Excel and paste the entry in there
or insert it without recourse to the clipboard or manual intervention, but
sadly I don't know much about the Excel model.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

I see events overtook me while I nipped out for a break ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top