Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 4605 toggling TrackRevisions in VBA 1

Status
Not open for further replies.

McGinley57

Technical User
Feb 12, 2008
16
US
Posted this to the MS Office Application Errors forum, but got no reply. Any help here at Tek-Tips would be greatly appreciated.

Intermittent problem: My code (see below) results in a 4605 error message when called from a button click sub. The button click sub is run when a user clicks a button control I've placed on a Word .docm page.

If I record a macro from within the document that toggles TrackRevisions, there is no error and I can run the macro as much as a I want with no trouble. However, once I go back and run the button click sub, I start getting the error again, even when I run the previously OK macro.

See the bottom of this post for the full code for the button click sub.

Maybe it's the act of bringing an Excel window to the forefront, then bringing the document forward, that's creating the problem?

Sub TurnOffRevisionTracking()
ActiveDocument.TrackRevisions = False
End Sub

Sub TurnOnRevisionTracking()
ActiveDocument.TrackRevisions = True
End Sub

Private Sub Get_Range_Click()
Dim wbTMWorkbook As Excel.Workbook
Dim rTMRangeToCopy As Excel.Range
Set dChangeRequestDocument = ThisDocument

' Check to see if target Excel workbook is open.
If Not IsTMOpen() Then
MsgBox ("Territory Master workbook is not open.")
Exit Sub
End If

' Load the workbook to a variable.
Set wbTMWorkbook = GetTMBook()

' Bring the workbook to the fore.
FnSetForegroundWindow (p_TMNAME & "*")

' Have the user select and submit a range.
On Error Resume Next
Set rTMRangeToCopy = wbTMWorkbook.Application.InputBox("Select items you want to request change for:", _
"Find Unique Values", Type:=8)
On Error GoTo 0

' Bring target document to fore.
FnSetForegroundWindow (ThisDocument.Name & "*")
If rTMRangeToCopy Is Nothing Then
Exit Sub
End If

' Copy source workbook range to clipboard.
rTMRangeToCopy.Copy

' Turn off revision tracking.
TurnOffRevisionTracking

' Perform paste actions.

' Turn on revision tracking.
TurnOnRevisionTracking

End Sub
 
Sorry 'bout that. The error occurs when I try to access and toggle the TrackRevisions property for the active document:

ActiveDocument.TrackRevisions = False

and

ActiveDocument.TrackRevisions = True
 


TrackRevisions is a MS Word property, not an MS Excel property, AFAIK.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What about changing this:
ActiveDocument.TrackRevisions = False
with this ?
ThisDocument.TrackRevisions = False

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
No, I've tried the ThisDocument vs. ActiveDocument approach. No luck.

It's very weird. I can see the property in the locals window, but its value is: TrackRevisions : <This command is not available.> : Boolean

 
1. Why are you doing this:
Code:
' Bring target document to fore. FnSetForegroundWindow (ThisDocument.Name & "*")
You can perform actions on a not visible Word file.

2. Are you sure all your variables are properly declared? You have:
Code:
Private Sub Get_Range_Click()

Dim wbTMWorkbook As Excel.Workbook
Dim rTMRangeToCopy As Excel.Range
Set dChangeRequestDocument = ThisDocument
but dChangeRequestDocument is not declared in this procedure. Is it somewhere else? Are you using Option Explicit?

3. I am not fully following exactly what document is doing what. Therefore, I would suggest using document objects
If dChangeRequestDocument is the ActiveDocument, then use ActiveDocument.

If you are trtying to perform actions on a different document (and I am not sure you are), you could possibly change your toggling procedures to:
Code:
Sub TurnOffRevisionTracking(oDocIn As Document)
   oDocIn.TrackRevisions = False
End Sub
Sub TurnOnRevisionTracking(oDocIn As Document)
   oDocIn.TrackRevisions = True
End Sub
Now you call the procedures for any given document you like: ActiveDocument, some othe rdocument - as long as it is open. It does NOT - repeat NOT - have to be active or visible.

Code:
' if dChangeRequestDocument is SET to a valid object
Call TurnOffRevisionTracking(dChangeRequestDocument)

'  OR
Call TurnOffRevisionTracking(ActiveDocument)


Gerry
 
1. Why are you doing this:
Code:
' Bring target document to fore. FnSetForegroundWindow (ThisDocument.Name & "*")
You can perform actions on a not visible Word file.

2. Are you sure all your variables are properly declared? You have:
Code:
Private Sub Get_Range_Click()

Dim wbTMWorkbook As Excel.Workbook
Dim rTMRangeToCopy As Excel.Range
Set dChangeRequestDocument = ThisDocument
but dChangeRequestDocument is not declared in this procedure. Is it somewhere else? Are you using Option Explicit?

3. I am not fully following exactly what document is doing what. Therefore, I would suggest using document objects
If dChangeRequestDocument is the ActiveDocument, then use ActiveDocument.

If you are trtying to perform actions on a different document (and I am not sure you are), you could possibly change your toggling procedures to:
Code:
Sub TurnOffRevisionTracking(oDocIn As Document)
   oDocIn.TrackRevisions = False
End Sub
Sub TurnOnRevisionTracking(oDocIn As Document)
   oDocIn.TrackRevisions = True
End Sub
Now you call the procedures for any given document you like: ActiveDocument, some othe rdocument - as long as it is open. It does NOT - repeat NOT - have to be active or visible.

Code:
' if dChangeRequestDocument is SET to a valid object
Call TurnOffRevisionTracking(dChangeRequestDocument)

'  OR
Call TurnOffRevisionTracking(ActiveDocument)
In any case, if you pass the document object itself in as a parameter you can possibly avoid your 4605 error. It some times is caused by the document not being visible or active.

Gerry
 
First off, thank you for such a thoughtful response.

To address your questions/suggestions (based on your numbering):

1. FnSetForegroundWindow is a function to bring any window specified to the forground. In this case, I'm using it to bring forward the Word document window after having previously brought forward an open Excel window.

2. This is a mistake on my part. I am not using Option Explicit at the moment and didn't declare the variable. I have since declared it, but doing so has not eliminated the root problem of not being able to toggle TrackRevisions.

3. I thought this was a great suggestion, but after implementing I receive the same error. For some reason the TrackRevsions property, and only that property, is rendered inaccessible by my approach of toggling it using a button (actually, a checkbox). The property is accessible and changeable through recording a macro of the steps (actually, just one) of turning revision tracking on. I can then replay that macro to my heart's content; however, when I copy the macro code over into my button-click sub, I get the 4605 error.

I'm at the point that I'm willing to concede the error might not be avoidable and will have to take another tact with my code.

Thanks again for your help.
 
1. FnSetForegroundWindow is a function to bring any window specified to the forground. In this case, I'm using it to bring forward the Word document window after having previously brought forward an open Excel window. "

Yes, I understand that...but my question was WHY?????

"is rendered inaccessible by my approach of toggling it using a button (actually, a checkbox)."

Make up your mind. Is it a button or a checkbox. AND, why is the Sub named TurnOffRevisionTracking. If it is a ActiveX control, the sub will be Commandbutton1_Click, or Check_Click, or something like that.

However, this is all rather moot, but you are correct.

It don't like it. It is worse than that...

I have a document with a commandbutton. Its code is:
Code:
Private Sub CommandButton1_Click()
   ActiveDocument.TrackRevisions = False
End Sub
Simple, right?

Not so fast.

I check. Tools > Track Changes is available, it is NOT greyed out.

I click the button.

I get a 4605 error. And............

Track Changes is now greyed out (as well as Compare). However, this does not happen all the time. You can get the items back (not greyed out) by simply moving the Selection (cursor) any where. Further, even copying Microsoft Help code:
Code:
With ActiveDocument
    .TrackRevisions = True
    .ShowRevisions = True
End With
fails with a 4605. Until you run it a second time, then it does. Also:
Code:
ActiveDocument.TrackRevisions = Not ActiveDocument.TrackRevisions
fails, then does not fail, then fails, then does not fail.


Damned if I know. Although I do know that I am finding this rather unreliable!

So, you gurus here...what gives?


Never mind, I got it. It has something to do with the location of the Selection. Because when you click a control Selection is at THAT control. Now WHY it fails, I am still not sure. However, all you have to do to not get the 4605 error is move the Selection, like this:
Code:
Private Sub CommandButton1_Click()
   Selection.Move Unit:=wdCharacter, Count:=1
   ActiveDocument.TrackRevisions = False
End Sub
No 4605 error.

Gerry
 
That fixed it! No error message! Thanks for all this.

I'm guessing that when the user clicks the button, the button retains focus and the property is rendered inaccessible. The selection.move action then moves it off focus? Whatever the explanation, thanks again.

And apologies for the earlier confusion.
 
Hi McGinley57,

in accordance to the rules of this page I have a question:
I think fumei* deserves a star, doesn't he? In my eyes he's the (only) one who found out the actually underlying problem.

M.
_________________
* I'm wondering where "fumei" comes from: 1) there is no resemblance to "Gerry", 2) the "ei" sounds very German but he seems to be English. And I'm also wondering where his site with "My paintings and pictures" has gone.
 
I'm wondering where "fumei" comes from: 1) there is no resemblance to "Gerry", 2) the "ei" sounds very German but he seems to be English. And I'm also wondering where his site with "My paintings and pictures" has gone.

fumei is:

1. Catonese for "bitter taste"

2. Japanese for "unknown"

3. an old influential Italian family

4. the name of my grey cat, as I did not want to name him fume (French for smoke)

It is pronounced (in Cantonese): FOO-may

I have no idea how it is pronounced in Japanese.

English? NEVER! Just kidding. Scots on both sides. I just missed being born in Glascow. My mother was pregnant with me when my parents immigrated to Canada.

My painting and sculpture site? Dead and gone since I stopped having Internet access at home (a year and a half now). I can not do anything like that through my work access, since the firewall here is tighter than...well....

Gerry
 
Oh, and
I'm guessing that when the user clicks the button, the button retains focus and the property is rendered inaccessible. The selection.move action then moves it off focus?
That is correct. For some reason, TrackChanges is not accessible when focus is on an ActiveX control (ANY control!). You can easily see this.


Make a ActiveX textbox. Toggle DesignMode so the cursor is blinking IN the textbox. Now look at the Tools menu.

Track Changes is greyed out.

VOILA!

Why this is...shrug...darned if I know. It is a toggle, it changes a state, a Boolean property of the document. What that has to do with focus being on an ActiveX control is beyond me. After all:
Code:
Private Sub CommandButton1_Click()
ActiveDocument.BuiltInDocumentProperties(wdPropertyAuthor) _
   = "Yadda"
End Sub
works just fine. I wonder if it has to do with it being a Boolean property of the dcoument, but I can not prove this.




Nope. That is not it. I just tried a few Boolean properties, and they work with no 4605 errors.

Shrug. I believe it is just going to have to be one of "those things".

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top