Solved

determine if word document was opened by another document

Posted on 2014-12-16
5
106 Views
Last Modified: 2014-12-17
continuation of this question

Word 2003:
Currently I have code in document 1 to open a second document based on a template:
Documents.Add "document2.dot"

document2.dot has a Sub Document_New() routine.

I would like to run one set of code in document2.dot if document2.dot is opened by double clicking on it but run a different set of code if it is opened from document 1.  Document 1 could have any name.

for example:
Sub Document_New()
   If opened from document 1 then
       do this
   else
       do this instead
   end if
End Sub

Any way to do that?
0
Comment
Question by:thenelson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40503270
You could try setting a time flag in the registry and testing it to make sure that it isn't an old setting:
Sub NewDocFromDoc2()
    Dim doc As Document
    SaveSetting "MyApp", "Opening", "Time", CStr(Now)
    Set doc = Documents.Add("C:\Users\Graham Skan\Documents\Doc2.dotm")
End Sub

Open in new window

Sub Document_New()
Dim dt As Date
dt = CDate(GetSetting("MyApp", "Opening", "Time", "1/1/1900"))
    If DateDiff("s", dt, Now) < 2 Then
        MsgBox "Opened from Doc1"
    End If
End Sub

Open in new window

0
 
LVL 39

Author Comment

by:thenelson
ID: 40503965
Neat idea. I guess I could use DeleteSetting after GetSetting in the second document and then I wouldn't need to check the time.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40504416
Yes, that would work as well.
0
 
LVL 39

Author Comment

by:thenelson
ID: 40504631
So this is what I did and it is working fine:

Calling document:
SaveSetting "Script", "Open", "Ptname", ActiveDocument.Bookmarks("PatientsName").Range.Text
SaveSetting "Script", "Open", "DOB", Format(ActiveDocument.Bookmarks("DOB").Range.Text, "mm/dd/yyyy")

Documents.Add ("Document2.dot")

Open in new window

Document2.dot:
Dim strName As String, strDOB As String

strName = GetSetting("Script", "Open", "Ptname")
If Len(strName & "") Then
    strDOB = GetSetting("Script", "Open", "DOB")
    DeleteSetting "Script", "Open"
Else
    'the other stuff
End If

Open in new window

0
 
LVL 39

Author Closing Comment

by:thenelson
ID: 40504638
Thanks, works great.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question