PDA

View Full Version : Help a surgeon automate morning rounds, MS Word VBA



IFITFITSITFI
06-01-2017, 04:43 PM
Hello,

I am shamelessly posting in this forum because I am in a bit over my head and I need some help. I am a medical student in my surgery rotation and our team relies heavily on a document called "The List." This document is a word document that contains a table where each row represents a specific patient we are taking care of in the hospital. Unfortunately I can't post actual patient data but I've tried to attach an example of what I'm working with here. The problem is that every morning the list needs to be updated to reflect the status of all the patients prior to rounds at 6am. To do this manually requires going to the electronic medical record (EMR) and copying and, for the most part, pasting the updated information relevant to the team into the word document for each patient. This is very time consuming and mindless. In the EMR you can generate an uptodate PDF report of all patients the team is covering, and this contains much of the data in The List. What I would like to one day do is be able to generate the report, open The List, press a button and have all the fields in the list updated with data from the report. More realistically, I just want the vital signs to be updated. What I've been trying to do is simply ctrlA and copy the report to the empty pages beneath The List in its word doc, then design some macro that let's me click on the field in The List for vitals, execute macro, and have it search the pasted report for the correct patient from that row and copy and paste the vitals in to where my cursor is, with the messy pdf-to-word format cleaned up. I would then do this for each row (or this could all be done in loop) and be done in 5 minutes instead of 30. I'm sure there's a more elegant way to do this, but I just wanted to describe my goals here. This article on this site "Macro-to-find-string-and-copy-sentence-containing-string" seemed to have some of the functionality I need, but I've been able to find nothing so far that is close enough to my problem that I can modify it to my needs on my own.

I would appreciate any help you all can offer, and I wish I had the time to work through this on my own since it seems like a fun problem whose solution would really help a lot of people (I work at a major hospital and every surgical team uses the same list document). Thank you in advance!

19370

gmaxey
06-01-2017, 05:03 PM
Yes, considering what Medicare, private insurance or the patient (out of pocket) is likely paying for the hospital services, your request is pretty shameless. Until you can provide a "List" before and after some event and the data source, it is going to hard for anyone here to do anything even if they would.

IFITFITSITFI
06-01-2017, 05:46 PM
Yes, considering what Medicare, private insurance or the patient (out of pocket) is likely paying for the hospital services, your request is pretty shameless. Until you can provide a "List" before and after some event and the data source, it is going to hard for anyone here to do anything even if they would.

Sounds like my request hit a nerve with you greg, but if you are hoping to take a dig at someone who profits from the system then your rudeness is misplaced-I am unpaid and deep in debt. Ill work on providing the info you mention, but if anyone else can help get me started with code to select and copy a number of lines of text following a specific selected patient name, for example, I'd be well on my way. Also I'll happily credit anyone in this work. In reality this will likely be just for myself and maybe future med students.

gmaxey
06-01-2017, 06:11 PM
I'm rude because I agreed with you?


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
With Selection
.Expand wdLine
.MoveEnd wdParagraph, 26
.Copy
End With
lbl_Exit:
Exit Sub
End Sub

IFITFITSITFI
06-01-2017, 06:48 PM
I'm not sure anymore but regardless, thanks for the reply--this is a helpful start. I've updated the example with more specifics.

mdmackillop
06-03-2017, 12:43 PM
If you could complete one record showing the finished product that would make things clearer

IFITFITSITFI
06-04-2017, 12:45 PM
Hello,

Thanks for the help again. I was able to make a macro that does what I need so I'll post it here in case anyone else has a similar need in the future.


Sub vitals()
'Written by Sam T.
'A clunky macro to update vitals in the rounding list
'Thanks to Greg Maxey for his help writing this code
'first need to set the selected text (pt name) as the querrey and look for the next instance of it, which will be
'right before the vitals to be copied
Dim qry As String
Dim vitals As String
qry = Selection.Text
With Selection.Find
.Forward = True
.Wrap = wdFindStop
.Text = Selection
.Execute
End With
'this section copies the vitals, which are consistently several lines below the pt name in report
With Selection
.Expand wdLine
.MoveEnd wdLine, 8
.MoveStart wdLine, 3
.Copy
End With
vitals = Selection.Text
Selection.Collapse
'now need to go back to the pt name from the list, 2 find commands since we need to go 2 instances up
With Selection.Find
.ClearFormatting
.Text = qry
.Execute Forward:=False
End With
Selection.Collapse
With Selection.Find
.ClearFormatting
.Text = qry
.Execute Forward:=False
End With
Selection.Collapse
'now moving to the row where vitals are to be pasted
If Selection.Information(wdWithInTable) = True Then
Selection.Cells(1).Next.Select
End If
If Selection.Information(wdWithInTable) = True Then
Selection.Cells(1).Next.Select
End If
If Selection.Information(wdWithInTable) = True Then
Selection.Cells(1).Next.Select
End If
'typing the vitals in
With Selection
.TypeText Text:=vitals
.MoveUp wdLine, 3, Extend:=wdExtend
.Collapse wdCollapseStart
End With
'a little formatting to make it look better
Selection.MoveLeft Extend:=wdExtend
Selection.Delete
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:=" "
lbl_Exit: Exit Sub
End Sub