PDA

View Full Version : Script to insert script in document created from a template



Chetanh
02-05-2008, 09:50 AM
Hi,
I have to create a word template such that i have the following script embedded in the document created from the template

ActiveWindow.View.ShadeEditableRanges = False


Basically the user wants that the shading on editable ranges should be disabled when a document is created out of the template. The user does not want to go through the process of doing this manually each time the document is created.

Any ideas on how this can be done will be greatly appreciated.

Thanks,
Chetanh

fumei
02-06-2008, 10:16 AM
Not quite following. Plus, you must be using a different version - please mention version when posting, thanks - as ShadeEditableRanges is not something in 2002.

I am not even sure what an editable range may be.

Nelviticus
02-07-2008, 04:49 AM
ShadeEditableRanges is available in Office 2007. It's mentioned in the VBA help files, which haven't been updated since Office 2003 so I assume it was introduced with that version. Anyway, the following code should do it: Public Sub AutoNew() ActiveWindow.View.ShadeEditableRanges = False End Sub Apologies for the freaky layout, the post editor seems to be misbehaving for me today.

fionabolt
02-07-2008, 05:38 AM
Chetanh

You probably want to stop the yellow highlighting when the document is opened later as well, in which case you would also need:
Public Sub AutoOpen()
ActiveWindow.View.ShadeEditableRanges = False
End Sub

Chetanh
02-07-2008, 06:50 AM
Thanks for your replies



I tried this. After pasting the code in the template i get the following message while trying to compile

Expected Function or variable.
And the ActiveWindow text gets highligted.

The code looks like below in script editor:


Sub ActiveWindow()
ActiveWindow.View.ShadeEditableRanges = False
End Sub
Sub AutoOpen()
ActiveWindow.View.ShadeEditableRanges = False
End Sub

Sub AutoNew()
ActiveWindow.View.ShadeEditableRanges = False
End Sub

fionabolt
02-07-2008, 07:07 AM
Chetanh

Which instance of ActiveWindow gets highlighted?

I bet it's
Sub ActiveWindow()

That is because you have given the procedure the same name as an MS Property.

I don't know when you intend to call this procedure, but I suspect you do not need it at all. The AutoNew procedure will switch off the highlighting when you create a new document with the template and the AutoOpen procedure will switch off the highlighting when you open the document.

Solution: either delete the sub ActiveWindow() or rename it.

Chetanh
02-07-2008, 08:04 AM
Thanks for your reply..
Just to confirm, we are using Office 2003 SP3

Well it works great, but it still dosent solve my original problem.

I have inserted this code in a word teplate.
When the user opens this template he editable ranges are not highlighted.
However when the document is saved a opened by someone else, the editable ranges are highlighted again.
I want a macro to be inserted in the created document so that the ediable ranges are never highlighted.

fionabolt
02-08-2008, 04:38 AM
Chetanah

Who is the other user? Someone else within the same firm or a client elsewhere?

If it's someone in the same firm, then give then the template too.

If it's someone elsewhere, then you have an issue. If you write code in the template to include the procedure into the document, and then email the document, most firewalls will reject the attachement as potentially dangerous.

Regards,
Fiona