• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

Template workflow assistance

I have a workflow process with which working with a Word Template, I need to accomplish the following:

Save the Active Document to a predefined location depended upon the users selection in the form.
Close the document.
Open a new instance based upon the template.

The users are opening the template in the standard way (click on a shortcut, recieve a Document1 [2,3,4,etc]).

Currently I have the first two requirements completed.  The Document instance of the template is saved to the location and closed.  But when it gets to the point of creating the new instance, nothing happens.  I understand why it is happening (When the ActiveDocument.Close method fires, it closes the document instance and it's attatched TemplateProject instance leaving just a Normal Template instance running).  I have tried to open a new document instance using a method placed in Normal (really not the preferred way I would like to take this), but this too has proven a little more difficult to accomplish.

Any assistance would be greatly appreciated.

-saige-
Sub NextDocument()
    Dim strTempData As String
    strPath = "P:\"
    strAppPath = TemplateProject.ThisDocument.Path & "\Surgery Form.dot"
    strDocTitle = ActiveDocument.FormFields("Text1").Result & " " _
    & Replace(ActiveDocument.FormFields("Text17").Result, "/", "-")
    Select Case ActiveDocument.FormFields("AttendDoctor").Result
        Case "Dr. Lawrence Mandel"
            strPath = strPath & "Surgery Scheduling\"
        Case "Dr. William Cruce"
            strPath = strPath & "Surgery Scheduling-Dr. Cruce\"
        Case Else
            MsgBox ("A doctor was not selected.  Please select a doctor and try again.")
            Exit Sub
    End Select
    strSaveString = strPath & strDocTitle & ".doc"
    With ActiveDocument
        .SaveAs FileName:=strSaveString
        .Close
    End With
    MsgBox ("File has been saved to: " & strSaveString & _
    "  Please continue.")
    Documents.Add Template:=strAppPath, NewTemplate:=False
End Sub

Open in new window

0
weareit
Asked:
weareit
  • 3
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
Have you tried opening the new document before saving and closing the previous one?
0
 
weareitAuthor Commented:
I have not tried that, it really seems convaluted to accomplish this that way but Microsoft is not known for always taking the logical path when providing a development path.

How would you recommend accomplishing this?

By moving the Documents.Add Template:=strAppPath, NewTemplate:=False line above the With ActiveDocument line?

If so, how would I then reference the previous document to once again make it the ActiveDocument (since opening a new instance is going to automatically provide focus to the new instance)?

-saige-
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Just jumping here.... maybe the following code?  Although Graham is MUCH better at this stuff than I am...

Sub NextDocument()
    Dim strTempData As String
    strPath = "P:\"
    strAppPath = TemplateProject.ThisDocument.Path & "\Surgery Form.dot"
    strDocTitle = ActiveDocument.FormFields("Text1").Result & " " _
    & Replace(ActiveDocument.FormFields("Text17").Result, "/", "-")
    Select Case ActiveDocument.FormFields("AttendDoctor").Result
        Case "Dr. Lawrence Mandel"
            strPath = strPath & "Surgery Scheduling\"
        Case "Dr. William Cruce"
            strPath = strPath & "Surgery Scheduling-Dr. Cruce\"
        Case Else
            MsgBox ("A doctor was not selected.  Please select a doctor and try again.")
            Exit Sub
    End Select
    strSaveString = strPath & strDocTitle & ".doc"
    With ActiveDocument
        .SaveAs FileName:=strSaveString
        .Close
    End With
    MsgBox ("File has been saved to: " & strSaveString & _
    "  Please continue.")
     'NEW CODE HERE
    tFormLetter = ActiveDocument.Name
    Documents.Add Template:=strAppPath, NewTemplate:=False
    tNewLetter = ActiveDocument.Name
    Documents(tFormLetter).Close savechanges:=wdSaveChanges
    Documents(tNewLetter).Activate
End Sub

Open in new window

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
weareitAuthor Commented:
Thanks I'll try that but I think I'll have to make a change or two to the code you provided:

Sub NextDocument()
    Dim strTempData As String
    strPath = "P:\"
    strAppPath = TemplateProject.ThisDocument.Path & "\Surgery Form.dot"
    strDocTitle = ActiveDocument.FormFields("Text1").Result & " " _
    & Replace(ActiveDocument.FormFields("Text17").Result, "/", "-")
    Select Case ActiveDocument.FormFields("AttendDoctor").Result
        Case "Dr. Lawrence Mandel"
            strPath = strPath & "Surgery Scheduling\"
        Case "Dr. William Cruce"
            strPath = strPath & "Surgery Scheduling-Dr. Cruce\"
        Case Else
            MsgBox ("A doctor was not selected.  Please select a doctor and try again.")
            Exit Sub
    End Select
    strSaveString = strPath & strDocTitle & ".doc"
    With ActiveDocument
        .SaveAs FileName:=strSaveString
    'These below would be removed
    '    .Close
    'The above would be removed
    End With
    MsgBox ("File has been saved to: " & strSaveString & _
    "  Please continue.")
     'NEW CODE HERE
    tFormLetter = ActiveDocument.Name
    Documents.Add Template:=strAppPath, NewTemplate:=False
    tNewLetter = ActiveDocument.Name
    Documents(tFormLetter).Close savechanges:=wdSaveChanges
    Documents(tNewLetter).Activate
End Sub

Open in new window

0
 
weareitAuthor Commented:
Thanks, the modifications you made worked perfectly.  I did have to make the change that I thought I would, but overall a quick and concise solution.
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Wonderful!  Thanks so very much...glad to have been of assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now