Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-19-2016, 11:01 AM
GregL GregL is offline Word prompts to save template Windows 7 64bit Word prompts to save template Office 2010 32bit
Novice
Word prompts to save template
 
Join Date: Jun 2011
Posts: 12
GregL is on a distinguished road
Default Word prompts to save template

I'm automating Word 2013 from Excel 2013. Excel directs Word to:

- Create a new document based on a template I had previously set up.
- Update the links in the Excel chart objects embedded in the document.
- Break the links in those Excel chart objects (so that those charts become part of a static report and don't update with someone else's data).

The user can run the project in two modes: running a single report, and running a batch of reports. In batch mode, it saves and closes those files. There are no problems with the Word docs made during batch mode.

The problem is in one-by-one mode, which leaves the report open and unsaved for the user. If the user does nothing but close the document without saving it, they are prompted to save changes in the template. Then, after the document closes, they are prompted AGAIN to save changes in the same template, while Word is showing that it has no documents open.

I've tried setting the template's Saved property to True, but it doesn't help.

(BTW if they save the new document, close it, reopen it, and close it again, it doesn't prompt them to save the template then.)



If I manually double-click on the template file, so that Word opens a new document based on it, and then manually close the new document, Word does NOT prompt to save the template.

I could give the user a browse dialog and prompt them to save the file, but one possible reason for running the one-by-one mode in the first place is if they just want to take a quick look at a report without saving it.

What can I do to make Word stop prompting to save the template?

Also, why would it prompt TWICE to save the same template??

Here's the code. Everything is declared, though some of these are declared further up; I have Option Explicit on. full_path_to_renewal_report_word_template is passed in to the function:

Code:
 
        Dim oWord As Object, oDoc As Object, oEmbeddedExcelChart As Object, oLinkFormat As Object, oInlineShape As Object
        Dim dblOldWidth As Double, dblOldHeight As Double, dblNewHeight As Double
        Dim iChartsCount As Long, iChartIndex As Long
        Const SET_LINKED_OJBECTS_WIDTH As Long = 468
        Set oWord = GetWord
        Set oDoc = oWord.Documents.Add(Template:=full_path_to_renewal_report_word_template)
        If bIsBatchMode Then oWord.WindowState = 0: DoEvents 'wdWindowStateNormal
        oWord.Visible = True
        iChartsCount = oDoc.InlineShapes.Count
        For iChartIndex = 1 To iChartsCount 'can't use for/next loop through inlineshapes collection; doesn't work with embedded xl chart objects; error after first item in collection.
        Set oInlineShape = oDoc.InlineShapes(iChartIndex)
        Set oLinkFormat = oInlineShape.LinkFormat
            If Not oLinkFormat Is Nothing Then
                oLinkFormat.Update
                DoEvents
                dblOldWidth = oInlineShape.Width: dblOldHeight = oInlineShape.Height
                oInlineShape.Width = SET_LINKED_OJBECTS_WIDTH
                oInlineShape.Height = SET_LINKED_OJBECTS_WIDTH * (dblOldHeight / dblOldWidth)
                DoEvents
                oDoc.InlineShapes(iChartIndex).LinkFormat.BreakLink
                DoEvents
            End If
        Next iChartIndex
        'set the template to saved so it won't prompt to save: (this doesn't help though)
        Dim oTemplate As Object
        Set oFile = FSO.GetFile(full_path_to_renewal_report_word_template)
        For Each oTemplate In oWord.Templates
        If oTemplate.Name = oFile.Name Then
            oTemplate.Saved = True
            Exit For
        End If
        Next oTemplate
        '1x1 mode; leave the word doc open and unsaved for the user:
        oWord.WindowState = 0: DoEvents 'wdWindowStateNormal
        oDoc.Activate: DoEvents
        oWord.Activate: DoEvents
        Set oWord = Nothing: Set oDoc = Nothing: Set oTemplate = Nothing: Set oEmbeddedExcelChart = Nothing: Set oLinkFormat = Nothing: Set oInlineShape = Nothing
Due to the urgency of this issue, and not getting a response on my first post of it, I've posted wherever it seemed relevant:
- http://stackoverflow.com/questions/4...-save-template
- http://www.vbaexpress.com/forum/show...040#post354040
- http://www.excelforum.com/showthread...49#post4545449

Last edited by GregL; 12-19-2016 at 04:15 PM.
Reply With Quote
  #2  
Old 12-19-2016, 03:08 PM
macropod's Avatar
macropod macropod is offline Word prompts to save template Windows 7 64bit Word prompts to save template Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: http://www.excelforum.com/showthread...59#post4545559
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word prompts to save template Constant prompts to save Normal.dotm Teeafit Word 2 08-03-2015 02:07 PM
Just highlighting prompts save feature sassiebrat Word 0 07-20-2015 04:57 PM
Word ask to save template whenever i save a derived document jorbjo Word 3 10-04-2012 10:52 AM
Outlook 2007 prompts to save opened attachments OfficeAppentice Outlook 0 11-03-2011 09:24 AM
Word prompts to save template Word 2003 > close > it asks to save a global template tom8750 Word 10 05-23-2011 03:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft