Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2012, 07:45 AM
tonywatsonmail tonywatsonmail is offline Code to stop as "save as" if the mail merge has not been done Windows 7 32bit Code to stop as "save as" if the mail merge has not been done Office 2007
Novice
Code to stop as "save as" if the mail merge has not been done
 
Join Date: Jun 2011
Posts: 10
tonywatsonmail is on a distinguished road
Unhappy Code to stop as "save as" if the mail merge has not been done

Hi Everyone,

I've got a bit of a problem, Hope someone can help me!

Ive created a Number of Word Documents as "Template" Letters and use Mailmerge to create the Actual Documents using Data from access,

This works perfectly to as you all know to create the document you just, open the template, got to mailmerge, "merge single record" and you have the document all nice and easy you then save the merged document to the relevent client.

the problem I have is some of the people in my office are so stupid they can even follow these simple instructions and just save the "template" Document unmerged! which you can imagine when you then email it the a customer they cant open it because its not merged and cant find the data.



can someone give me some code that I could use to stop them from saving the "Template" maybe with a message box saying "You have not merged document, please merge document before trying to save!"

any help would be greatly appreciated

Thanks

Tony
Reply With Quote
  #2  
Old 04-24-2012, 05:25 PM
macropod's Avatar
macropod macropod is offline Code to stop as "save as" if the mail merge has not been done Windows 7 64bit Code to stop as "save as" if the mail merge has not been done Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 Tony,

You could try hooking into Word's 'before save' event. See:
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-25-2012, 07:32 AM
tonywatsonmail tonywatsonmail is offline Code to stop as "save as" if the mail merge has not been done Windows 7 32bit Code to stop as "save as" if the mail merge has not been done Office 2007
Novice
Code to stop as "save as" if the mail merge has not been done
 
Join Date: Jun 2011
Posts: 10
tonywatsonmail is on a distinguished road
Default

Thanks for you help , but I can't wright code, tried and fail everytime.

was hoping someone might help me out! could realy do with the help

Tony
Reply With Quote
  #4  
Old 04-27-2012, 01:48 AM
macropod's Avatar
macropod macropod is offline Code to stop as "save as" if the mail merge has not been done Windows 7 64bit Code to stop as "save as" if the mail merge has not been done Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 Tony,

Using Events requires that you instantiate the app object class. To do this, create a new class module in your mailmerge main document to register the desired Word events. At the top of the module put:
Code:
Public WithEvents wdApp As Word.Application
Public WithEvents wdDoc As Word.Document
Below that, add the following code to intercept the save event:
Code:
Private Sub wdApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
If Doc.MailMerge.MainDocumentType <> wdNotAMergeDocument Then
  MsgBox "This is the mailmerge main document," & vbCr & _
  "not the output document." & vbCr & vbCr & _
  "Do not send this document to the client.", vbExclamation
End If
End Sub
 
Private Sub wdApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Dim Rslt As Variant
If Doc.MailMerge.MainDocumentType <> wdNotAMergeDocument Then
  Rslt = MsgBox("This is the mailmerge main document," & vbCr & _
  "not the output document." & vbCr & vbCr & _
  "Do not send this document to the client." & vbCr & vbCr & _
  "Continue Saving?", vbOKCancel)
End If
If Rslt = vbCancel Then Cancel = True
End Sub
The above code should give the messages you desire.

Then, in a normal code module, put:
Code:
Dim wdAppClass As New ThisApplication
Public Sub AutoExec()
Set wdAppClass.wdApp = Word.Application
End Sub
This code will allow the events in your Word document to be called.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-27-2012, 01:57 AM
tonywatsonmail tonywatsonmail is offline Code to stop as &quot;save as&quot; if the mail merge has not been done Windows 7 32bit Code to stop as &quot;save as&quot; if the mail merge has not been done Office 2007
Novice
Code to stop as &quot;save as&quot; if the mail merge has not been done
 
Join Date: Jun 2011
Posts: 10
tonywatsonmail is on a distinguished road
Default

Hi Peter,

Thank you so very much, this is exactly what I needed.

and again

Thank You!

Tony :-)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
hit okay to "Merge to E-mail" nothing happened mubi_masti Outlook 0 10-21-2011 03:06 PM
Code to stop as &quot;save as&quot; if the mail merge has not been done How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM
Can I stop the right click "move here" feature? BillAnderson PowerPoint 0 04-16-2011 02:42 PM
How to stop "replace"'ing new words (in desperate need of advice) bme081 Word 6 11-02-2009 05:57 AM
VBA Code for making "mailings" tab active jandrade15 Mail Merge 0 08-01-2009 09:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:36 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