Macro won't run on "read only" document.

W

wendeclare

I have assigned a simple sorting macro to my word 2007 table. The document
is save in a file that has the access locked down making it "read only" to
anyone who does not have access to change the document. I have set the macro
security to low, but still can't get them to run for anyone who does not have
access to change. Is there a way to get around this problem?
 
W

Wraithchilde

I think I'd need to actually see the macro and need more information on how
you're using it, but you could try unprotecting the document in the beginning
of the macro and protecting it again at the end.
 
W

wendeclare

This is one of the macros. I recorded it rather than actually typing it in.
Do you mean save it elsewhere, assigning the macros, and then overwriting the
old document?

Sub QSD()
'
' QSD Macro
' Macro recorded 12/7/2006 by PMI
'
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Sort ExcludeHeader:=False, FieldNumber:="Column 5", _
SortFieldType:=wdSortFieldAlphanumeric,
SortOrder:=wdSortOrderAscending, _
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric,
SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending,
Separator:= _
wdSortSeparateByCommas, SortColumn:=False, CaseSensitive:=False, _
LanguageID:=wdEnglishUS, SubFieldNumber:="Paragraphs",
SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
Selection.HomeKey Unit:=wdStory
End Sub
 
L

Lisa

I think what was meant is to add some code to unprotect the document at the
beginning of your macro, and add code to reprotect it at the end of your
macro.

For example, you might insert the following at the beginning of your code
("yourpassword" being whatever password you're using):
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="yourpassword"
End If

And put this at the end of your code to put the doc back to read-only:
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyReading, Password:="yourpassword"
End If
 
W

wendeclare

The document is not password protected, because it is in a restricted folder.
I have access to change it through my I.T. department because I own the
document, but others only have viewing rights.
 
L

Lisa

I suspect, but am not certain sure, that users with only viewing right will
not be able to use a macro to sort the table columns... I tried various
approaches to using sort on a table -- all of them worked when the document
was unprotected, but I received an error when the document was "locked for
editing."

Keep in mind that I'm pretty much a novice, so there may be a workaround
that isn't apparent to me... but the obvious approaches seem a no-go.
 
R

Rob

Ok, I'm lost here. Are you saying the document is NOT protected? If not then
we can forget about the other suggestion.

Where is this document located? Is it on a SharePoint? Macros commonly won't
run from those. I'm not sure if the admin can change any settings, but it
seems like you should figure out how to give the doc to the users so the
macro will run.
 
W

wendeclare

Thank you Lisa. I'm not very well-versed in the background stuff either.

Rob, the document is on a shared drive, but the folder it is required to be
in is locked down for editing. I have editing rights because I own the
document, but others only view a "read only" copy. I would love to change it
to an Excel document, but that's not an option either. (My boss won't have
it.)

Do you have any suggestions?
 
R

Rob

Maybe you could put the code in a toolbar and give it to the users? Then they
could use it on any document, unless it's protected (the document not the
drive) in which case you'd have to add the unprotect/protect code to the
macro.
 
W

wendeclare

Unfortunately, it isn't protected by a code. It's more like a drive within a
drive. The main drive is the company share drive open for all to view and
even save info to, but the folder that I am required to keep this document in
is like another drive that everyone can see, but only a handful can change.
It's locked down for editing by our IT department. I have access to edit and
save the document, but not to remove this security.

The document is not password protected in any way, it just comes up as "read
only" in the active title bar when it's opened by those with viewing rights
only. They can type on the document, but when it comes to saving changes,
they cannot overwrite the saved original. People can even sort the document
on their own.

I've been tasked with trying to make it easier, because Word can be rather
jumpy, and my viewers aren't always very good at manipulating their view to
suit their needs.

Do you have any suggestions?
 
L

Lisa

I just noticed something in your original post that may hold the key to the
problem...

You say "I set the macro security to low..."
I'm pretty sure that the macro security level applies to the user's Word
installation -- not to a document. This means you set YOUR macro security
level for Word to low. You had no affect on others' macro security level.

It's possible that others have no success running the macro because their
security level is on High.

If others (with restricted/read-only) access can type in the file, but
cannot save changes, they should be able to run a macro to sort the table, if
they have macros enabled.

You might ask someone else to change their Word macro security level to
Medium, click "enable macros" when prompted when they open the doc, then see
if they can run your macro.

That said, I believe the following might work better for sorting the table.
(The macro you have requires they have their cursor in a table.)

This will sort the first table in the doc based on the entries in the fifth
column of the table. (It also doesn't include the first row in the sorting...
If you want to include the first row, replace "ExcludeHeader:=True" with
"ExcludeHeader:=False")

ActiveDocument.Tables(1).Sort ExcludeHeader:=True, FieldNumber:="Column 5", _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending, _
CaseSensitive:=False
 
W

wendeclare

I had one of my testers try your suggestion, and it still doesn't work.

Your statement about "viewers" being able to type in the document but not
save over the original version is exactly the reason why I thought this was a
"no brainer."

Thanks for the suggested change. It works great for me...
 
L

Lisa

A puzzle... I can run the macro here on read-only docs...

Is the macro in the document itself? (Just wondering if it might be in a
template that's on your system...)

After setting macro security to medium, did your tester receive a prompt re.
enabling macros? (And are you certain sure he clicked "enable"? ;-)

How do you trigger the macro (click a button, select Run on the Macros
dialog box, etc.)?

What happens when the "viewers" try to run the macro? If they receive an
error msg, what is it?
 
R

Rob

wendeclare said:
Unfortunately, it isn't protected by a code. It's more like a drive within a

Just to clarify, I suggested you put the code (i.e., VBA code, macro) in a
toolbar for the users rather than in the document. Then the users can run the
macro on any document, assuming they have the toolbar loaded and the document
has a table that the code can work with.
 
W

wendeclare

I have been doing some testing with different people, and it seems that
everyone was having trouble with my setup because the macros were assigned to
keyboard combinations ALT+C, ALT+D, & ALT+Q. I thought because the macros
were assigned to the document, even if these key combinations had another
purpose, they would work for my document.

I changed the formating on the table and made it so that the regular sorting
feature could be used.

Thank you both for all of your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top