Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Word Makro

Posted on 2014-11-24
4
127 Views
Last Modified: 2014-11-24
I have created a word document with form protected text boxes and assigned a makro with a keyboard shortcut that unprotects and reprotects the sheet after it goes to the end of the document, and I enters a specified auto text.  However, the makro doesn't produce an outcome  (nothing changes) with some random text to be insterted.

So here my questions:

How do I assign the  autotext "abc" instead of the random text?
And what, if anything is wrong with the makro, since it doesn’t work? one reason I could come up with might be that a macbook does not have an EndKey. Does that matter?

So this is the current Makro:

Sub Macro3()
Set aDoc = ActiveDocument
If aDoc.ProtectionType <> wdNoProtection Then
 aDoc.Unprotect
    Selection.EndKey Unit:=wdStory
Set aDoc = ActiveDocument
If aDoc.ProtectionType <> wdNoProtection Then
 aDoc.Unprotect
 Selection.InsertBefore "department six"
 aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword
End If
End Sub

thanks.
0
Comment
Question by:mvp1985
  • 3
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40463131
It the document is not protected then the code will do nothing
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40463143
If it is protected, you remove the protection, then you test it again. That test will be false and so nothing will be done.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40463159
Try this instead:
Sub Macro3a()
    Dim aDoc As Document
    Dim strPassword As String
    
    strPassword = "Pass"
    Set aDoc = ActiveDocument
    If aDoc.ProtectionType <> wdNoProtection Then
        aDoc.Unprotect strPassword
    End If
    aDoc.Bookmarks("\EndOfDoc").Range.Text = "department six"
    aDoc.Protect Type:=wdAllowOnlyFormFields, Password:=strPassword
 End Sub

Open in new window

0
 

Author Closing Comment

by:mvp1985
ID: 40463911
Solved my first question, but not my second
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question