Re: VBA macro stops executing on Word 2003 but works on Word XP
- From: MDIH EMR <MDIHEMR@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 21 Apr 2009 07:21:06 -0700
Thank you Graham,
I will be testing later today
"Graham Mayor" wrote:
It is not necessary to unprotect the form, which is as well because your.
code does not unprotect the document (but it does appear to make the form
unstable). That aside, assuming the paths for the document and the template
for the new document exist, the code does indeed work in Word 2003. However,
I think you may do better with:
Dim PatFullName() As String
Dim ProvPath As String
Dim DateofSVc As String
Dim PatFirstName As String
Dim PatLastName As String
Dim ProgNotePathAndFileName As String
Dim FileSavedAs As String
' Load name from form into work area
PatFullName = Split(ActiveDocument.FormFields("PatName").Result,
Chr(32))
' Load Provider Name into ProvPath var
ProvPath = ActiveDocument.FormFields("ProvName").Result
' Load Date of Service from form into DateofSvc var
DateofSVc = ActiveDocument.FormFields("DoS").Result
' Load first name into new variable
PatFirstName = PatFullName(0)
' Load patient last name into new variable
PatLastName = PatFullName(1)
' Build file save as path
ProgNotePathAndFileName = "\\mdihcpsi\users\Transcription\CFP Mona
York\Local " _
& ProvPath & "\To Be Printed " & ProvPath & "\" & DateofSVc & " " _
& PatLastName & " " & PatFirstName & ".doc"
' Save file
ActiveDocument.SaveAs ProgNotePathAndFileName
' Build message confirming file save
FileSavedAs = "Progress Note saved as " & ProgNotePathAndFileName
' Display confirmation
MsgBox FileSavedAs
' Build path and file name for new document template
TemplatePath = "C:\Progress Note Templates\Prog Note " _
& ProvPath & ".dot"
' Open new document
Documents.Add Template:=TemplatePath
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
MDIH EMR wrote:
Here is the code. It stops executing immedately after the save file.
Thanks
' Unprotect form
ActiveDocument.Sections(1).ProtectedForForms = False
' Load name from form into work area
PatFullName = ActiveDocument.FormFields("PatName").Range.Text
' Load Provider Name into ProvPath var
ProvPath = ActiveDocument.FormFields("ProvName").Range.Text
' Load Date of Service from form into DateofSvc var
DateofSvc = ActiveDocument.FormFields("DoS").Range.Text
' Protect form
ActiveDocument.Sections(1).ProtectedForForms = True
' Find end of first name string
Firstspace = InStr(PatFullName, " ")
' Load first name into new field
PatFirstName = Left(PatFullName, Firstspace - 1)
' Delete first name from full name string
PatFullName = Mid(PatFullName, Firstspace + 1)
' Load patient last name into new field
PatLastName = PatFullName
' Build file save as path
ProgNotePathandFileName = "\\mdihcpsi\users\Transcription\CFP Mona
York\Local " & ProvPath & "\To Be Printed " & ProvPath & "\" &
DateofSvc & " " & PatLastName & " " & PatFirstName & ".doc"
' Save file
ActiveDocument.SaveAs ProgNotePathandFileName
' Build message confirming file save
FileSavedAs = "Progress Note saved as " & ProgNotePathandFileName
' Display confirmation
MsgBox FileSavedAs
' Build path and file name for new document template
TemplatePath = "C:\Progress Note Templates\Prog Note " & ProvPath
& ".dot"
' Open new document
Documents.Add Template:=TemplatePath
"MDIH EMR" wrote:
I have a macro that extracts information from a protected form,
assembles a file name and path, saves the file, prints the file and
then opens a new document using the template file. On Word XP the
macro executes completely. On Word 2003 the macro goes away after
the file is saved. I can see the difference in that after the file
is saved the macro code is no longer attached. Any suggestions?
- References:
- VBA macro stops executing on Word 2003 but works on Word XP
- From: MDIH EMR
- RE: VBA macro stops executing on Word 2003 but works on Word XP
- From: MDIH EMR
- Re: VBA macro stops executing on Word 2003 but works on Word XP
- From: Graham Mayor
- VBA macro stops executing on Word 2003 but works on Word XP
- Prev by Date: Re: VBA macro stops executing on Word 2003 but works on Word XP
- Next by Date: RE: Inline ScaleHeight/ScaleWidth returns 0 in Word 2007
- Previous by thread: Re: VBA macro stops executing on Word 2003 but works on Word XP
- Next by thread: Inline ScaleHeight/ScaleWidth returns 0 in Word 2007
- Index(es):
Relevant Pages
|