shelbypereira
shelbypereira

Reputation: 2245

VB macro to disable "Edit Document" prompt when opening a word document from sharepoint

Is there a way to disable the message (and have the document editable by default):

Server Document To modify document, click Edit Document followed by the button with text "Edit Document".

I cannot find a word setting to do this. In addition I cannot see a way to make a VB macro to do this with a key stroke. I have used a small autohotkey script to position the mouse and click this prompt, but this does not always work since it depends on the position of the window. it is impossible to use the tab key to get to this prompt.

I have to modify about 50+ documents a day from sharepoint, ideally I would like to combine this with another macro which does other automated processing for me. But I can't find a VB solution for clicking the Edit button.

Upvotes: 0

Views: 1120

Answers (1)

Comintern
Comintern

Reputation: 22195

Depending on your security settings (you mentioned that they were blocked), this may or may not work.

Create a new macro enabled template in your Word startup folder (usually at C:\Users[YourID]\AppData\Roaming\Microsoft\Word\STARTUP), and add a new class module. I called mine "AutoEditEnable". You can name it anything, but you'll need it to match how you declare it in the other module.

This code goes in the class:

Option Explicit
Private WithEvents app As Application

Private Sub Class_Initialize()

    Set app = Application

End Sub

Private Sub app_ProtectedViewWindowOpen(ByVal PvWindow As ProtectedViewWindow)

    PvWindow.Edit

End Sub

Basically, this will hook any Application events you need to - in this case the ProtectedViewWindowOpen event or the ProtectedViewWindowActivate event (either should work).

Put the following code in ThisDocument to grab a reference to it when your template loads:

Option Explicit
Private hook As AutoEditEnable

Private Sub Document_Open()

    Set hook = New AutoEditEnable

End Sub

Close Word and restart it, then make sure your new template shows up as a loaded add-in.

Upvotes: 2

Related Questions