Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2014, 08:41 AM
KSReynolds KSReynolds is offline Program Word to Save File As... Windows 7 32bit Program Word to Save File As... Office 2003
Novice
Program Word to Save File As...
 
Join Date: Oct 2013
Posts: 7
KSReynolds is on a distinguished road
Default Program Word to Save File As...


Is there a way to program a merged word document to save as a filename? I have tried to do this through access coding and I am 99.99% effective, but once in a while, the File Save As box pops open prompting the user to save the file. Thanks.
Reply With Quote
  #2  
Old 08-15-2014, 09:08 AM
Charles Kenyon Charles Kenyon is offline Program Word to Save File As... Windows 7 64bit Program Word to Save File As... Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,459
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I routinely do it, but the merged document is (1) merged as a part of a macro, (2) attached to a separate template following the merge (through that macro), and then that template has an intercept for the SaveAs and Save commands. (It also finishes by attaching the merged document to the normal template.)
Reply With Quote
  #3  
Old 08-15-2014, 09:12 AM
KSReynolds KSReynolds is offline Program Word to Save File As... Windows 7 32bit Program Word to Save File As... Office 2003
Novice
Program Word to Save File As...
 
Join Date: Oct 2013
Posts: 7
KSReynolds is on a distinguished road
Default So...

My Access application opens up the new word document based on the template as a new document and then merges it. The merge works fine. How do I intercept the file save as then.... I can't believe someone else does this! Would it be code I put in the template?
Reply With Quote
  #4  
Old 08-15-2014, 09:16 AM
KSReynolds KSReynolds is offline Program Word to Save File As... Windows 7 32bit Program Word to Save File As... Office 2003
Novice
Program Word to Save File As...
 
Join Date: Oct 2013
Posts: 7
KSReynolds is on a distinguished road
Default My Code

This is my code from Access:

Dim myfilename As String
myfilename = ReportDir & LabNumber & "_" & ItemNumber & "_" & CATEGORY & ".doc"
Dim mypassword As String
mypassword = DecryptPIN(DLookup("PIN_NUMBER", "ANALYST", "FULL_NAME='" & ana_txt & "'"))
'save to temp directory
wordapp.ActiveDocument.SaveAs filename:=myfilename, WritePassword:=mypassword
wordapp.ActiveDocument.Close
Reply With Quote
  #5  
Old 08-15-2014, 03:23 PM
macropod's Avatar
macropod macropod is offline Program Word to Save File As... Windows 7 32bit Program Word to Save File As... Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
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

See 'Send Mailmerge Output to Individual Files' and 'Split Merged Output to Separate Documents' in the Sticky thread (https://www.msofficeforums.com/mail-...ps-tricks.html) at the top of the mailmerge forum (I've moved this discussion there).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 08-16-2014, 04:01 AM
Charles Kenyon Charles Kenyon is offline Program Word to Save File As... Windows 7 64bit Program Word to Save File As... Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,459
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by KSReynolds View Post
My Access application opens up the new word document based on the template as a new document and then merges it. The merge works fine. How do I intercept the file save as then.... I can't believe someone else does this! Would it be code I put in the template?
The procedure I use is as follows:

  1. I do not create a new document based on a template. I open an existing document that was saved as a non-merge document.
  2. The vba attaches the data file from a standard location. It always has the same name: Names.txt.
  3. It performs a merge to a new result document and closes the original document without saving.
  4. It attaches the new document to a template.
  5. That template has a custom ribbon of procedures.
  6. At the beginning of the first procedure it saves to a designated folder and proposes a name that starts with the standard name for the document and adds the days date in the format yyyy-mm-dd.
  7. It uses the FileSaveAs dialog. My procedure displays the dialog with the suggested name. Instead, the dialog could just execute. Go here for references.
  8. The final step includes removing some special formatting (some merge fields are hot pink) and attaching the document to the normal template.
The procedure for intercepting Word commands (FileSave and FileSaveAs) can be found at Intercepting events like Save and Print on the MVP website. Those macros would be in the temporarily attached template named as FileSave and FileSaveAs.

Because my code is scattered in different templates it would be a major effort to rewrite it for what you are doing.

Here is code putting the current date as a tag at the end of the suggested name when saving a new document. I have this in a template. It is sometimes a nuisance, but most files I create I like to put the date as a tag.

Code:
Public Sub SaveWithDate(Optional strName As String)
    ' Run as substitute for FileSave to add date to default document names
    ' Put in a global template as public macro
    ' Call this from other templates
    ' If strName is supplied, it is used as the base name, otherwise the base comes from the Title Property
        On Error Resume Next
   
    If Len(ActiveDocument.Path) > 0 Then
      ' The document has already been saved at least once.
      ' Just save and exit the macro.
      ActiveDocument.Save
      Exit Sub
    End If
    '
    If strName = "" Then strName = strName & ActiveDocument.BuiltInDocumentProperties("Title").Value        'get name in title
    
    Dim dlgSave As Dialog
    Set dlgSave = Dialogs(wdDialogFileSaveAs)
    strName = strName & " " & Format((Year(Now() + 1) Mod 100), "20##") & "-" & _
        Format((Month(Now() + 1) Mod 100), "0#") & "-" & _
        Format((Day(Now()) Mod 100), "0#")
    ActiveDocument.BuiltInDocumentProperties("Title").Value = strName
    ActiveDocument.BuiltInDocumentProperties("Company").Value = "Kenyon Law Office"
    With dlgSave
        .Name = strName
        .Show
        
    End With
End Sub

Sub FileSave()
    Application.Run "SaveWithDate"
End Sub

Sub FileSaveAs()
    Application.Run "SaveWithDate"
End Sub
[code]

Again, if I just wanted it to automatically save the file with the chosen name, I would use .Execute instead of .Show.
Reply With Quote
  #7  
Old 09-21-2014, 07:25 AM
macropod's Avatar
macropod macropod is offline Program Word to Save File As... Windows 7 64bit Program Word to Save File As... Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
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

Hi Charles,

Question: What are you trying to achieve with this:
Code:
        Format((Year(Now() + 1) Mod 100), "20##") & "-" & _
        Format((Month(Now() + 1) Mod 100), "0#") & "-" & _
        Format((Day(Now()) Mod 100), "0#")
instead of, say:
Code:
        Format(Date, "YYYY-MM-DD")
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Program Word to Save File As... Word VBA - Save file as a string contained within the word (always same row and leng) RG87 Word VBA 1 05-21-2014 05:39 AM
How do I save a Word file with a macro for distribution? leemoreau Word VBA 3 10-04-2013 08:06 AM
Program Word to Save File As... Word Mail Merge File Save mickeyw3340 Mail Merge 2 12-18-2012 11:30 AM
Program Word to Save File As... MS Word XP file save wayne Word 8 08-15-2011 03:56 PM
Program Word to Save File As... Word Macro: Save file as text with current file name jabberwocky12 Word VBA 2 10-22-2010 12:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:47 PM.


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