Word application activedocument protect

 +1 

   

Распечатать

Как открыть из 1С документ Word без возможности его редактирования и копирования?

Код 1C v 8.х

 Если НЕ РольДоступна("ПолныеПрава") Тогда
Word.Application.ActiveDocument.Protect(2,ИСТИНА,Строка(Код),Ложь,ИСТИНА);//пароль на редактрование - код текущего объекта
ВордВасик=Word.WordBasic;
Сообщить(ВордВасик.MsgBox("Документ открыт только для чтения!",));
ДобавитьОбработчик Word.DocumentBeforeSave, ОбработкаСохраненияДокумента;
КОнецЕсли;
....

Процедура ОбработкаСохраненияДокумента(Doc, SaveAsUI, Cancel)
Cancel = True;
ВордВасик=Word.WordBasic;
Сообщить(ВордВасик.MsgBox("Вам запрещено сохранять документ!",));
КонецПРоцедуры
// Печать соответственно DocumentBeforePrint

   Икогнито

22.10.09 — 15:05

Как включить защиту документа Word из 1С с помощь макроязыка Word?

   also

1 — 22.10.09 — 15:10

Блин запиши макрос и выполни из 1с…По-моему Protect()

   Mirid

2 — 22.10.09 — 15:15

Protect(«пароль»)

   Икогнито

3 — 22.10.09 — 15:33

Внутри макроса ворда команда выглядит так:

ActiveDocument.Protect(wdAllowOnlyFormFields,[NoResef],[Password],[EnforceStyleLock])

Как её, блин написать из 1С с учетом wdAllowOnlyFormFields и пароля?

   Икогнито

4 — 22.10.09 — 15:48

up

   Икогнито

5 — 22.10.09 — 16:01

гз

   dk

6 — 22.10.09 — 16:02

двоешник

   dk

7 — 22.10.09 — 16:02

тебе точно уперлось wdAllowOnlyFormFields?

   Икогнито

8 — 22.10.09 — 16:06

(7) точно, при ней нельзя даже скопировать текст в буфер обмена

   dk

9 — 22.10.09 — 16:08

1. открой Word

2. Alt+F11

3. F2

4. введи там wdAllowOnlyFormFields и поиск

там будет написано чему это в цифрах равно

   Икогнито

10 — 22.10.09 — 16:10

(9)В редакторе макросов ворда:

Sub Макрос3()



‘ Макрос3 Макрос





ActiveDocument.Protect wdAllowOnlyFormFields

End Sub

Как дальше задать пароль и все остальное?

   Икогнито

11 — 22.10.09 — 16:11

+(10) все остальное, это [NoResef],[Password],[EnforceStyleLock])

   Икогнито

12 — 22.10.09 — 16:12

(9) wdAllowOnlyFormFields  не находит

   Икогнито

13 — 22.10.09 — 16:15

Const wdAllowOnlyFormFields = 2

Member of Word.WdProtectionType

Из одынеса пишем

ActiveDocument.Protect(3,

а это где ищем и как прописываем?

[NoResef],[Password],[EnforceStyleLock])

   StarIK2005

14 — 22.10.09 — 16:15

Эти в квадратных скобках — из перечислений. Банально флаги. ИМХО их сумма даст какое-нить 0FFFFFFH, чем и стоит воспользоваться.

   dk

15 — 22.10.09 — 16:16

в 2007-м нету метода протект



навскидку

МойДокумент.Protect(2,»МойСуперПароль»);

   dk

16 — 22.10.09 — 16:17

процитируй из VBA что в хелпе по методу Protect написано

   Fish

17 — 22.10.09 — 16:18

MSWord.Application.ActiveDocument.Protect(3,Ложь,ПарольДокумента,Ложь,Ложь);
работает в 2003-м на 100%

   lxs

18 — 22.10.09 — 16:31

отмечусь

   Икогнито

19 — 22.10.09 — 16:40

(17) спасибо, доперло

Но в самом ворде почему-то конструкция со скобками не прокатывает ActiveDocument.Protect(3,Ложь,ПарольДокумента,Ложь,Ложь)

   Икогнито

20 — 22.10.09 — 16:41

(15) есть в 2007-м метод протект

   Fish

21 — 22.10.09 — 16:43

(19) Естественно не прокатывает. «Ложь» — это для 1С булево, а для ворда это просто строка :)

   Икогнито

22 — 22.10.09 — 17:12

(21) да про «Ложь» я и не говорю

(20) может и есть, только не у Document класса

Using VBA, I believe you’d be looking for the protect method:

Application.ActiveDocument.Protect wdAllowOnlyRevisions, password:="password"

With protect, you can specify the type of protection, the password, and various components of the protection (style lock, resetting of form fields, etc.).
More on protect can be found here.

Likewise, VBA has a similar method for unprotecting a Word document, if you know the password. This is the aptly named unprotect method.

Application.ActiveDocument.Unprotect "password"

More on unprotect can be found here.

Как открыть из 1С документ Word без возможности его редактирования и копирования?

Код 1C v 8.х

 Если НЕ РольДоступна("ПолныеПрава") Тогда
      
Word.Application.ActiveDocument.Protect(2,ИСТИНА,Строка(Код),Ложь,ИСТИНА);//пароль на редактрование - код текущего объекта
ВордВасик=Word.WordBasic;
Сообщить(ВордВасик.MsgBox("Документ открыт только для чтения!",));
ДобавитьОбработчик Word.DocumentBeforeSave, ОбработкаСохраненияДокумента;
КОнецЕсли;
....

Процедура ОбработкаСохраненияДокумента(Doc, SaveAsUI, Cancel)
Cancel = True;
ВордВасик=Word.WordBasic;
Сообщить(ВордВасик.MsgBox("Вам запрещено сохранять документ!",));
КонецПРоцедуры
// Печать соответственно DocumentBeforePrint

Подпишитесь на нашу рассылку новостей

Хотите узнать больше по этому вопросу?

Подпишитесь на нашу рассылку новостей

Подписаться

Чтобы задать вопрос или предложить тему статьи, нажмите на кнопку ниже:

Предложить статью

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;

namespace VSTO
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Open document
            Microsoft.Office.Interop.Word.Application wordApp = Application;
            wordApp.Documents.Open("../../Sample.docx");

            //Protect the document
            object noReset = false;
            object password = "E-iceblue";
            object useIRM = false;
            object enforceStyleLock = false;
            this.Application.ActiveDocument.Protect(Word.WdProtectionType.wdAllowOnlyReading,
            ref noReset, ref password, ref useIRM, ref enforceStyleLock);
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spire.Doc
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load Document
            Document doc = new Document("../../Sample.docx");

            //Protect the document
            doc.Protect(ProtectionType.AllowOnlyReading, "E-iceblue");

            //Save and Launch
            doc.SaveToFile("Protect.docx");
            System.Diagnostics.Process.Start("Protect.docx");
        }
    }
}

Protect/Unprotect a Word Document using VBA, C#, VB.Net example

Protect/Unprotect

Prevent editing or deleting or adding contents in the word document. Considering that user is having sensitive information which he/she doesn’t wish to allow anyone to modify in the document. In this article we are using VBA, VSTO (Visual Studio Tools for office) in C# and VB.Net code style hence following prerequisites are recommended:

Syntax

Document.Protect(Type, NoReset, Password, UseIRM, EnforceStyleLock)

  1. Type: The type of protection to be applied
  2. NoReset: False to reset form fields to their default values; True to retain the current form field values if the document is protected. If Type is not wdAllowOnlyFormFieldsNoReset is ignored.
  3. Password: If supplied, the password to be able to edit the document, or to change or remove protection.
  4. UseIRM: Specifies whether to use Information Rights Management (IRM) when protecting the document.
  5. EnforceStyleLock: Specifies whether formatting restrictions are enforced for a protected document.

Lock Types are derived from WdProtectionType enum and has following constants:

Lock Types

  1. wdAllowOnlyComments: Only comment would be allowed
  2. wdAllowOnlyFormFields: Only form fields would be allowed
  3. wdAllowOnlyReading: Only reading would be allowed means no insertion, formatting, editing, deleting would be allowed
  4. wdAllowOnlyRevisions: track revision would be allowed
  5. wdNoProtection: no protection

C# Code example

private void btnProtect_Click(object sender, RibbonControlEventArgs e)
{
	//bind active document reference
	wordApp.Document oDocument = Globals.ThisAddIn.Application.ActiveDocument;

	//Protect document
	oDocument.Protect(wordApp.WdProtectionType.wdAllowOnlyReading,System.Reflection.Missing.Value,"password");

}

Unprotect

Document.Unprotect(“password”);

VB.Net code example

Private Sub btnProtectdocument_Click(sender As Object, e As RibbonControlEventArgs) Handles btnProtectdocument.Click
    
    'Declare document object variable
    Dim oDocument as word.Document
    
    'Set the reference of active document
    oDocument=Globals.ThisAddIn.Application.ActiveDocument
    
    'Perform protection
    oDocument.Protect(WdProtectionType.wdAllowOnlyReading,vbNull,"password")
End Sub

VBA code example

Public Sub ProtectDocumentExample()
    Dim oDocument As Document
    Set oDocument = ActiveDocument
    
    'Protect document for readonly
    oDocument.Protect wdAllowOnlyReading, , "password"
End Sub

Output

Next >> Document object a complete reference Word with VBA

Export Generic Collection to PDF ASP.Net Core MVC

Понравилась статья? Поделить с друзьями:
  • Word are very unnecessary they can only do harm
  • Word are unnecessary перевод
  • Word are silent слушать
  • Word are silent перевод песни
  • Word are silent outro