JBSMichael
11-07-2013, 04:53 AM
Hi all, new member here.
I have an issue with a Word 2010 .dotm template that contains code to import text from a .doc file held elsewhere in the same Sharepoint environment. The idea is simple enough: complete a table in the .doc file, then at a later date, create a .docx based on the .dotx that holds the code, click on a button and import some (populated) table text from the .doc to overwrite an (empty) table in the .docx. Both source and destination files look similar, with the relevant areas of table/text both being encapsulated in a bookmark called Part1Content.
The code in the template is held in the ThisDocument object. When the template is used to create a new document, what is created is a .docx (rather than a .docm), but the events and modules still run. The only issue seems to be that when I run this 'import' code by clicking the relevant button in the new document, the problem code appears to run (for example the desired text goes onto the clipboard) but nothing is pasted into the destination document. The real headache is that this has worked in the past but has stopped doing so and I don't know why.
Here is the code from the template:
Private Sub CommandButton2_Click()
Dim docMOD As Document
Dim doc As Document
Dim bkmTF As Bookmark
Dim bkmSGF As Bookmark
Dim rngTF As Range
Dim rngSGF As Range
Dim strLink As String
On Error Resume Next
ActiveDocument.Shapes("txtInstruction").Delete 'Get rid of instruction textbox
On Error GoTo 0
strLink = InputBox("Please paste a link to the Tasking Request file in the box below, then click OK. In the box that follows, click OK again.", "Source File", vbOKCancel)
If strLink = vbNullString Then Exit Sub
ThisDocument.FollowHyperlink (strLink)
Set docMOD = ActiveDocument
Set bkmTF = docMOD.Bookmarks("Part1Content")
Set rngTF = bkmTF.Range
Set bkmSGF = ThisDocument.Bookmarks("Part1Content")
Set rngSGF = bkmSGF.Range
rngTF.Copy
rngSGF.Select
Selection.Paste
docMOD.Close (False)
End Sub
I have copied this code into a normal module and run it - it works fine then.
Any ideas? I'm exhausted.
Thanks
Michael
I have an issue with a Word 2010 .dotm template that contains code to import text from a .doc file held elsewhere in the same Sharepoint environment. The idea is simple enough: complete a table in the .doc file, then at a later date, create a .docx based on the .dotx that holds the code, click on a button and import some (populated) table text from the .doc to overwrite an (empty) table in the .docx. Both source and destination files look similar, with the relevant areas of table/text both being encapsulated in a bookmark called Part1Content.
The code in the template is held in the ThisDocument object. When the template is used to create a new document, what is created is a .docx (rather than a .docm), but the events and modules still run. The only issue seems to be that when I run this 'import' code by clicking the relevant button in the new document, the problem code appears to run (for example the desired text goes onto the clipboard) but nothing is pasted into the destination document. The real headache is that this has worked in the past but has stopped doing so and I don't know why.
Here is the code from the template:
Private Sub CommandButton2_Click()
Dim docMOD As Document
Dim doc As Document
Dim bkmTF As Bookmark
Dim bkmSGF As Bookmark
Dim rngTF As Range
Dim rngSGF As Range
Dim strLink As String
On Error Resume Next
ActiveDocument.Shapes("txtInstruction").Delete 'Get rid of instruction textbox
On Error GoTo 0
strLink = InputBox("Please paste a link to the Tasking Request file in the box below, then click OK. In the box that follows, click OK again.", "Source File", vbOKCancel)
If strLink = vbNullString Then Exit Sub
ThisDocument.FollowHyperlink (strLink)
Set docMOD = ActiveDocument
Set bkmTF = docMOD.Bookmarks("Part1Content")
Set rngTF = bkmTF.Range
Set bkmSGF = ThisDocument.Bookmarks("Part1Content")
Set rngSGF = bkmSGF.Range
rngTF.Copy
rngSGF.Select
Selection.Paste
docMOD.Close (False)
End Sub
I have copied this code into a normal module and run it - it works fine then.
Any ideas? I'm exhausted.
Thanks
Michael