M
McGinley
Intermitent 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
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