F
Fuzzhead
I have documents that are created from a template but once they get up into
our system get delinked from the template. What I have done is when the
document is created it copies all the forms and macros into each document. My
question is how do I copy the following macros into 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)
'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 wdFirstPageHeaderStory 'wdPrimaryHeaderStory
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
frmTable.Show
Exit Sub
Case Else
If Sel.Range.InRange(ActiveDocument.Bookmarks("bktable").Range) Then
ActiveDocument.Bookmarks("bkbeforetbl").Select
frmTable.Show
End If
If Sel.Range.InRange(ActiveDocument.Bookmarks("bkProTitle").Range) Then
ActiveDocument.Bookmarks("bkbeforetbl").Select
frmType.Show
End If
End Select
End Sub
our system get delinked from the template. What I have done is when the
document is created it copies all the forms and macros into each document. My
question is how do I copy the following macros into 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)
'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 wdFirstPageHeaderStory 'wdPrimaryHeaderStory
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
frmTable.Show
Exit Sub
Case Else
If Sel.Range.InRange(ActiveDocument.Bookmarks("bktable").Range) Then
ActiveDocument.Bookmarks("bkbeforetbl").Select
frmTable.Show
End If
If Sel.Range.InRange(ActiveDocument.Bookmarks("bkProTitle").Range) Then
ActiveDocument.Bookmarks("bkbeforetbl").Select
frmType.Show
End If
End Select
End Sub