Reply
 
Thread Tools Display Modes
  #1   Report Post  
Keenly52
 
Posts: n/a
Default How do I create a macro to data sort in a table within a protecte.

I'm creating a user form in Word that includes a table to be sorted afterthe
user enters their info - specifically a sort on the "date" column.

The macro I created works fine in an unprotected doc, but not when it's
protected - which it will always be when being used by others.

I can't find a Word command to include in the macro unprotect the doc or the
selection ('ProtectedForForms = False' doesn't work in Word) ... I can't
create a macro in a protected document (I don't think), and when clicking on
"Protect Document" the macro stops recording.

Any help with a solution is greatly appreciated. Thanks.
  #2   Report Post  
Graham Mayor
 
Posts: n/a
Default

Try the following

'Unprotect the file
If ActiveDocument.ProtectionType wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If

Put your code here

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Keenly52 wrote:
I'm creating a user form in Word that includes a table to be sorted
afterthe user enters their info - specifically a sort on the "date"
column.

The macro I created works fine in an unprotected doc, but not when
it's protected - which it will always be when being used by others.

I can't find a Word command to include in the macro unprotect the doc
or the selection ('ProtectedForForms = False' doesn't work in Word)
... I can't create a macro in a protected document (I don't think),
and when clicking on "Protect Document" the macro stops recording.

Any help with a solution is greatly appreciated. Thanks.



  #3   Report Post  
Keenly52
 
Posts: n/a
Default

Thank you very much - looks like it will do the trick. Cheers

"Graham Mayor" wrote:

Try the following

'Unprotect the file
If ActiveDocument.ProtectionType wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If

Put your code here

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Keenly52 wrote:
I'm creating a user form in Word that includes a table to be sorted
afterthe user enters their info - specifically a sort on the "date"
column.

The macro I created works fine in an unprotected doc, but not when
it's protected - which it will always be when being used by others.

I can't find a Word command to include in the macro unprotect the doc
or the selection ('ProtectedForForms = False' doesn't work in Word)
... I can't create a macro in a protected document (I don't think),
and when clicking on "Protect Document" the macro stops recording.

Any help with a solution is greatly appreciated. Thanks.




  #4   Report Post  
Keenly52
 
Posts: n/a
Default

Graham - I hate to impose but I ran into a couple of snags - btw it's Office
2003.

VB didn't recognize the variable bProtected (I never got past the 2nd line).
Only certain sections are protected
I need to password the protection and the code

Also, while I have you - is there any way a Macro can look at the value of a
Form field check box and then trigger certain actions depending on that
value? Or would I require a Control check box for that? If you had sample
code that would be awesome.

Many thanks again. Ken.

"Graham Mayor" wrote:

Try the following

'Unprotect the file
If ActiveDocument.ProtectionType wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If

Put your code here

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Keenly52 wrote:
I'm creating a user form in Word that includes a table to be sorted
afterthe user enters their info - specifically a sort on the "date"
column.

The macro I created works fine in an unprotected doc, but not when
it's protected - which it will always be when being used by others.

I can't find a Word command to include in the macro unprotect the doc
or the selection ('ProtectedForForms = False' doesn't work in Word)
... I can't create a macro in a protected document (I don't think),
and when clicking on "Protect Document" the macro stops recording.

Any help with a solution is greatly appreciated. Thanks.




  #5   Report Post  
Keenly52
 
Posts: n/a
Default

Graham - as I should have earlier, I have moved my enquiry over to the
programming discussion. Thanks again for your assistance. Cheers.


  #6   Report Post  
Graham Mayor
 
Posts: n/a
Default

The methodology is explained at
http://word.mvps.org/faqs/macrosvba/...ProtectDoc.htm. There is also
code on the MVPS web site which will help you fire an action based on the
result of a checkbox field.


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




Keenly52 wrote:
Graham - I hate to impose but I ran into a couple of snags - btw it's
Office 2003.

VB didn't recognize the variable bProtected (I never got past the 2nd
line). Only certain sections are protected
I need to password the protection and the code

Also, while I have you - is there any way a Macro can look at the
value of a Form field check box and then trigger certain actions
depending on that value? Or would I require a Control check box for
that? If you had sample code that would be awesome.

Many thanks again. Ken.

"Graham Mayor" wrote:

Try the following

'Unprotect the file
If ActiveDocument.ProtectionType wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If

Put your code here

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Keenly52 wrote:
I'm creating a user form in Word that includes a table to be sorted
afterthe user enters their info - specifically a sort on the "date"
column.

The macro I created works fine in an unprotected doc, but not when
it's protected - which it will always be when being used by others.

I can't find a Word command to include in the macro unprotect the
doc or the selection ('ProtectedForForms = False' doesn't work in
Word) ... I can't create a macro in a protected document (I don't
think), and when clicking on "Protect Document" the macro stops
recording.

Any help with a solution is greatly appreciated. Thanks.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table in a Form HiDbLevel Tables 12 February 27th 06 12:59 PM
Specific Email Merge w/ Specific Attachements Mark B Mailmerge 9 February 21st 05 05:10 AM
How do I insert Excel data as a Word table and stay within margins Fritz Tables 1 February 6th 05 08:39 AM
Can't sort table alphabetically Tiffany Microsoft Word Help 1 January 21st 05 10:17 PM
Word 2003 Table AutoFormat vs Macro vs VBA Kind writer/user/programmer Tables 1 October 28th 04 03:14 PM


All times are GMT +1. The time now is 06:01 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"