none
Word Automation: Disable copy RRS feed

  • Question

  • I have an Access 2010 and via VBA call Word [template] to send text using Word automation. I am using the VBA properties Application.ActiveDocument and Application.ActiveWindow. Is it possible to do the following from Access and not modify the Word template:

    1. Go to the top of the document.
    2. Disable the ability to copy text.
    Thursday, August 11, 2011 1:32 PM

Answers

  • Hi Rick,

    Thanks for your post.

    Cindy is right, you have to use an add-in for disabling Cut & Copy feature. You can custom the ribbon of template via XML code to implement this, in this way, you don't need to worry about the security warning.

    Please following the steps below:

    Before customiziton the ribbon, you need to install CustomUI editor.

    You can download from here:

    http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2006/05/25/customuieditor.aspx

    Open the tool -> File -> Open -> Select your template -> OK -> Right click the template -> Office 2010 Custom UI part -> Insert the XML code below -> Save 

     

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
     <commands >
      <command idMso ="Copy" enabled ="false"/>
      <command idMso ="Cut" enabled ="false"/>
     </commands> 
    </customUI>
    

     

    Now you can open the template, you will see both Copy icon in ribbon and shortcut "Ctrl+c" have been disabled.

    I hope this helps.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Rick131 Wednesday, August 17, 2011 11:56 AM
    Friday, August 12, 2011 8:43 AM
    Moderator

All replies

  • Go to the top of the document, yes: Application.Selection.HomeKey Unit:=wdStory

    Disable the ability to copy text: No. You'd have to have some kind of Add-in (whether a template or COM add-in) to do that.


    Cindy Meister, VSTO/Word MVP
    Thursday, August 11, 2011 2:31 PM
    Moderator
  • To go to the top I also found this instruction Application.Selection.GoTo What:=wdGoToPage, Count:=1.

    The one you provided works great too. Thanks.

     

    Didn't really want to add any code into the Word template, because of the security warning that might pop up.

    Thursday, August 11, 2011 6:33 PM
  • Hi Rick

    What you could do is provide a separate template that contains any code you might need for your particular task. Have Access load that template as an "Add-in" (Application.Addins collection of the Word object model). Anything you load through your code shouldn't trigger a security measure because, if your code is running, it's "trusted".

    All the VBA code, toolbars/Ribbon, keyboard shortcuts and AutoTExt/Building blocks in that template will be available to Word at the application level as long as the template is loaded.

    At the end of your code, unload the template add-in again.


    Cindy Meister, VSTO/Word MVP
    Friday, August 12, 2011 8:23 AM
    Moderator
  • Hi Rick,

    Thanks for your post.

    Cindy is right, you have to use an add-in for disabling Cut & Copy feature. You can custom the ribbon of template via XML code to implement this, in this way, you don't need to worry about the security warning.

    Please following the steps below:

    Before customiziton the ribbon, you need to install CustomUI editor.

    You can download from here:

    http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2006/05/25/customuieditor.aspx

    Open the tool -> File -> Open -> Select your template -> OK -> Right click the template -> Office 2010 Custom UI part -> Insert the XML code below -> Save 

     

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
     <commands >
      <command idMso ="Copy" enabled ="false"/>
      <command idMso ="Cut" enabled ="false"/>
     </commands> 
    </customUI>
    

     

    Now you can open the template, you will see both Copy icon in ribbon and shortcut "Ctrl+c" have been disabled.

    I hope this helps.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Rick131 Wednesday, August 17, 2011 11:56 AM
    Friday, August 12, 2011 8:43 AM
    Moderator
  • I must create another new empty template and apply the XML shown above then call it via addin property in VBA?

    Downloaded Custom UI Editor, but am getting the error: "File contains corrupted data", when I try to open the template with it.

    Friday, August 12, 2011 1:55 PM
  • Hi Rick

    Mmmm. Did you open Word 2010 and save the new file as in the *.dotm file format?

    That's what you need to do before you open it in the Custom UI Editor.

    You don't HAVE to create a new template, but if you're worried about having a macro-enabled template when creating these documents, a separate template would be the way to go. You can also use the template your code is using - it shouldn't give a macro warning. But in order to add a Ribbon to it it does need to be *.dotm

    There's no need to CALL anything in the template, as far as the Ribbon goes. If you use Calvin's code it goes into effect as soon as Word loads that Ribbon.


    Cindy Meister, VSTO/Word MVP
    Friday, August 12, 2011 3:59 PM
    Moderator
  • I converted the DOT file into DOTM and ran Custom UI Editor to disbale the menus and options. Worked great and didn't give the security nag!

    I notice that DOTM only works in Word 2007 and up, is this correct?

    Monday, August 15, 2011 3:11 PM
  • Hi Rick

    Yes, it's correct that dotm only works in 2007 and later. But those are also the only versions where the "ribbon trick" for controlling the commands will work.

    If you also need to support earlier versions of Word you'll need another template, this time *.dot. In that you need macros with the "command name". If I recall correctly, that would be EditCopy and EditCut, so

    Sub EditCopy()
    End Sub

    Sub EditCut()
    End Sub

    Your Access VBA can check WordApplication.Version and load the appropriate template file as a WordApplication.Addin.


    Cindy Meister, VSTO/Word MVP
    Tuesday, August 16, 2011 10:09 AM
    Moderator
  • I created an IF routine to check if the version is greater than 11.0 then use the dotm template otherwise use the original dot template.

    I added the subs just as it was written in a module in the dot template and it worked!

     

    Thanks!

    Wednesday, August 17, 2011 4:09 PM
  • Hi Rick

    glad things are working out :-)!


    Cindy Meister, VSTO/Word MVP
    Wednesday, August 17, 2011 4:11 PM
    Moderator