[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Template workflow assistance

Posted on 2008-11-13
6
Medium Priority
?
599 Views
Last Modified: 2012-05-05
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
Comment
Question by:weareit
  • 3
  • 2
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22952651
Have you tried opening the new document before saving and closing the previous one?
0
 
LVL 12

Author Comment

by:weareit
ID: 22953087
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
 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 2000 total points
ID: 22953425
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
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
LVL 12

Author Comment

by:weareit
ID: 22954041
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
 
LVL 12

Author Closing Comment

by:weareit
ID: 31516485
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
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 22959771
Wonderful!  Thanks so very much...glad to have been of assistance.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question