F
Fuzzhead
I have the following macros in the ThisDocument of a Word Document that I am
having problems with. We have a third party program that we use to open Word
documents. When I open a document with these macros in it, it won’t work. But
if I have the original template opened and minimized it will work. Is there a
different way to do this without putting it in the ThisDocument?
Option Explicit
'reserve memory for an application variable
Private WithEvents wdApp As Word.Application
Private Sub Document_New()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub Document_Open()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)
Dim Group As Bookmark
'quit if active doc isn't attached to this template
If ActiveDocument.AttachedTemplate <> ThisDocument Then Exit Sub
'get out of the header if we're in it
Select Case Sel.StoryType
Case wdMainTextStory
If Sel.Range.InRange(ActiveDocument.Bookmarks("PL").Range) Then
ActiveDocument.Bookmarks("P1").Select
frmplan.Show
Set frmplan = Nothing
ElseIf Sel.Range.InRange(ActiveDocument.Bookmarks("CC").Range) Then
ActiveDocument.Bookmarks("C1").Select
frmCorc.Show
Set frmCorc = Nothing
ElseIf Sel.Range.InRange(ActiveDocument.Bookmarks("WC").Range) Then
ActiveDocument.Bookmarks("W1").Select
frmWC.Show
Set frmWC = Nothing
ElseIf Sel.Range.InRange(ActiveDocument.Bookmarks("AL").Range) Then
ActiveDocument.Bookmarks("A1").Select
frmRP.Show
Set frmRP = Nothing
End If
Exit Sub
End Select
End Sub
having problems with. We have a third party program that we use to open Word
documents. When I open a document with these macros in it, it won’t work. But
if I have the original template opened and minimized it will work. Is there a
different way to do this without putting it in the ThisDocument?
Option Explicit
'reserve memory for an application variable
Private WithEvents wdApp As Word.Application
Private Sub Document_New()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub Document_Open()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)
Dim Group As Bookmark
'quit if active doc isn't attached to this template
If ActiveDocument.AttachedTemplate <> ThisDocument Then Exit Sub
'get out of the header if we're in it
Select Case Sel.StoryType
Case wdMainTextStory
If Sel.Range.InRange(ActiveDocument.Bookmarks("PL").Range) Then
ActiveDocument.Bookmarks("P1").Select
frmplan.Show
Set frmplan = Nothing
ElseIf Sel.Range.InRange(ActiveDocument.Bookmarks("CC").Range) Then
ActiveDocument.Bookmarks("C1").Select
frmCorc.Show
Set frmCorc = Nothing
ElseIf Sel.Range.InRange(ActiveDocument.Bookmarks("WC").Range) Then
ActiveDocument.Bookmarks("W1").Select
frmWC.Show
Set frmWC = Nothing
ElseIf Sel.Range.InRange(ActiveDocument.Bookmarks("AL").Range) Then
ActiveDocument.Bookmarks("A1").Select
frmRP.Show
Set frmRP = Nothing
End If
Exit Sub
End Select
End Sub