Reply
 
Thread Tools Display Modes
  #1   Report Post  
Larry
 
Posts: n/a
Default How to make doc's FullName into an AutoText entry without first inserting it into document


This macro works fine. It temporarily Inserts Fullname of the active
document into the document and makes that string an AutoText entry
called MyDocName, which is used later by another macro to reactivate
this document from another document. This enables me to return
instantly to this document without having to open the Window menu or
scroll through the open documents. But I wonder if there is a more
efficient way of doing it, so that the active document's FullName
doesn't actually have to be inserted into the document as a range, but
rather the FullName becomes an AutoText entry in one step. It seems
that would make the macro a little faster.

Any ideas? Thanks.
Larry
..

Sub DocFullNameStore()

Application.ScreenUpdating = False
Dim X As Long, Y As Long
Dim r As Range

X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.FullName
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocFullName", Range:=r
r.Delete

End Sub



  #2   Report Post  
Jezebel
 
Posts: n/a
Default

Storing the name as a DocumentProperty or DocVariable would be simpler; but
if the name needs to be retained only for the current session, why not
simply put it into a static variable within your VBA module?


"Larry" wrote in message
...

This macro works fine. It temporarily Inserts Fullname of the active
document into the document and makes that string an AutoText entry
called MyDocName, which is used later by another macro to reactivate
this document from another document. This enables me to return
instantly to this document without having to open the Window menu or
scroll through the open documents. But I wonder if there is a more
efficient way of doing it, so that the active document's FullName
doesn't actually have to be inserted into the document as a range, but
rather the FullName becomes an AutoText entry in one step. It seems
that would make the macro a little faster.

Any ideas? Thanks.
Larry
.

Sub DocFullNameStore()

Application.ScreenUpdating = False
Dim X As Long, Y As Long
Dim r As Range

X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.FullName
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocFullName", Range:=r
r.Delete

End Sub





  #3   Report Post  
Larry
 
Posts: n/a
Default




The purpose of this is to be able to activate this document by a single
command from another document. How would putting a static variable
within the module enable me to do that?

So that you can better understand what I'm doing here, here is the
second macro, by which I activate the first document (the one whose name
has been made into an AutoText entry by the first macro) from another
document. What would be the equivalent of this using a variable instead
of an AutoText entry?

Sub PrevDocActivate()

' Open (or activate) the document whose name (or fullname) has been made
into an
' AutoText entry.

' Uses Activate method if document is open, and Open method is document
is closed.

'Application.ScreenUpdating = False

Dim sDoc As Document
Dim PrevDocName As String
PrevDocName = NormalTemplate.AutoTextEntries("MyDocFullName").Va lue
'Instead of opening in all cases, do a For Each statement.
For Each sDoc In Documents
If sDoc.FullName = PrevDocName Then
myFlag1 = True
Exit For
End If
Next
If myFlag1 = True Then

'DocFullNameStore

Documents(PrevDocName).Activate
Else
Documents.Open (PrevDocName)
End If

End Sub



Jezebel wrote:
Storing the name as a DocumentProperty or DocVariable would be
simpler; but if the name needs to be retained only for the current
session, why not simply put it into a static variable within your VBA
module?


"Larry" wrote in message
...

This macro works fine. It temporarily Inserts Fullname of the
active document into the document and makes that string an AutoText
entry called MyDocName, which is used later by another macro to
reactivate this document from another document. This enables me to
return instantly to this document without having to open the Window
menu or scroll through the open documents. But I wonder if there
is a more efficient way of doing it, so that the active document's
FullName doesn't actually have to be inserted into the document as
a range, but rather the FullName becomes an AutoText entry in one
step. It seems that would make the macro a little faster.

Any ideas? Thanks.
Larry
.

Sub DocFullNameStore()

Application.ScreenUpdating = False
Dim X As Long, Y As Long
Dim r As Range

X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.FullName
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocFullName", Range:=r
r.Delete

End Sub



  #4   Report Post  
Larry
 
Posts: n/a
Default

I guess my real question is, how do I put a variable in a function, so
that it can then be accessed later by a macro?

Then it would work like this. Macro 1 defines the FullName of the
active document as a variable, MyDocFullName. This variable is then
placed in a function. Then, after I've activated a different document,
I run Macro 2, which accesses the variable MyDocFullName from the
function and sticks it into a line of code:

Documents(MyDocFullName).Activate

Larry




Larry wrote:
The purpose of this is to be able to activate this document by a
single command from another document. How would putting a static
variable within the module enable me to do that?

So that you can better understand what I'm doing here, here is the
second macro, by which I activate the first document (the one whose
name has been made into an AutoText entry by the first macro) from
another document. What would be the equivalent of this using a
variable instead of an AutoText entry?

Sub PrevDocActivate()

' Open (or activate) the document whose name (or fullname) has been
made into an
' AutoText entry.

' Uses Activate method if document is open, and Open method is
document is closed.

'Application.ScreenUpdating = False

Dim sDoc As Document
Dim PrevDocName As String
PrevDocName = NormalTemplate.AutoTextEntries("MyDocFullName").Va lue
'Instead of opening in all cases, do a For Each statement.
For Each sDoc In Documents
If sDoc.FullName = PrevDocName Then
myFlag1 = True
Exit For
End If
Next
If myFlag1 = True Then

'DocFullNameStore

Documents(PrevDocName).Activate
Else
Documents.Open (PrevDocName)
End If

End Sub



Jezebel wrote:
Storing the name as a DocumentProperty or DocVariable would be
simpler; but if the name needs to be retained only for the current
session, why not simply put it into a static variable within your
VBA module?


"Larry" wrote in message
...

This macro works fine. It temporarily Inserts Fullname of the
active document into the document and makes that string an
AutoText entry called MyDocName, which is used later by another
macro to reactivate this document from another document. This
enables me to return instantly to this document without having to
open the Window menu or scroll through the open documents. But I
wonder if there is a more efficient way of doing it, so that the
active document's FullName doesn't actually have to be inserted
into the document as a range, but rather the FullName becomes an
AutoText entry in one step. It seems that would make the macro a
little faster.

Any ideas? Thanks.
Larry
.

Sub DocFullNameStore()

Application.ScreenUpdating = False
Dim X As Long, Y As Long
Dim r As Range

X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.FullName
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocFullName", Range:=r
r.Delete

End Sub



  #5   Report Post  
Jezebel
 
Posts: n/a
Default

Module level variable --

Dim mDoc as Word.Document


Sub Macro1()
:
set mDoc = ActiveDocument
:
End Sub


Sub PrevDocActivate
mDoc.Activate
End Sub


Bear in mind that while you're writing or debugging your code, mDoc will get
cleared whenever you make any changes to any code.






"Larry" wrote in message
...
I guess my real question is, how do I put a variable in a function, so
that it can then be accessed later by a macro?

Then it would work like this. Macro 1 defines the FullName of the
active document as a variable, MyDocFullName. This variable is then
placed in a function. Then, after I've activated a different document,
I run Macro 2, which accesses the variable MyDocFullName from the
function and sticks it into a line of code:

Documents(MyDocFullName).Activate

Larry




Larry wrote:
The purpose of this is to be able to activate this document by a
single command from another document. How would putting a static
variable within the module enable me to do that?

So that you can better understand what I'm doing here, here is the
second macro, by which I activate the first document (the one whose
name has been made into an AutoText entry by the first macro) from
another document. What would be the equivalent of this using a
variable instead of an AutoText entry?

Sub PrevDocActivate()

' Open (or activate) the document whose name (or fullname) has been
made into an
' AutoText entry.

' Uses Activate method if document is open, and Open method is
document is closed.

'Application.ScreenUpdating = False

Dim sDoc As Document
Dim PrevDocName As String
PrevDocName = NormalTemplate.AutoTextEntries("MyDocFullName").Va lue
'Instead of opening in all cases, do a For Each statement.
For Each sDoc In Documents
If sDoc.FullName = PrevDocName Then
myFlag1 = True
Exit For
End If
Next
If myFlag1 = True Then

'DocFullNameStore

Documents(PrevDocName).Activate
Else
Documents.Open (PrevDocName)
End If

End Sub



Jezebel wrote:
Storing the name as a DocumentProperty or DocVariable would be
simpler; but if the name needs to be retained only for the current
session, why not simply put it into a static variable within your
VBA module?


"Larry" wrote in message
...

This macro works fine. It temporarily Inserts Fullname of the
active document into the document and makes that string an
AutoText entry called MyDocName, which is used later by another
macro to reactivate this document from another document. This
enables me to return instantly to this document without having to
open the Window menu or scroll through the open documents. But I
wonder if there is a more efficient way of doing it, so that the
active document's FullName doesn't actually have to be inserted
into the document as a range, but rather the FullName becomes an
AutoText entry in one step. It seems that would make the macro a
little faster.

Any ideas? Thanks.
Larry
.

Sub DocFullNameStore()

Application.ScreenUpdating = False
Dim X As Long, Y As Long
Dim r As Range

X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.FullName
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocFullName", Range:=r
r.Delete

End Sub







  #6   Report Post  
Larry
 
Posts: n/a
Default

Fantastic, so simple.

There's one drawback however. This would work only with open documents.
My older macro, which uses the actual FullName of the document as an
AutoText entry, can also open a closed document.

However, this would still be great with an alternative: a macro that
will alternatively activate two documents. Let's say I have seven
documents open and I just want to go back and forth between two of them
for a while. Instead of having to deal with the Window menu or using
NextWindow to find the destination document each time, a simply macro
will do it.

Larry

Jezebel wrote:
Module level variable --

Dim mDoc as Word.Document


Sub Macro1()
:
set mDoc = ActiveDocument
:
End Sub


Sub PrevDocActivate
mDoc.Activate
End Sub


Bear in mind that while you're writing or debugging your code, mDoc
will get cleared whenever you make any changes to any code.






"Larry" wrote in message
...
I guess my real question is, how do I put a variable in a function,
so that it can then be accessed later by a macro?

Then it would work like this. Macro 1 defines the FullName of the
active document as a variable, MyDocFullName. This variable is then
placed in a function. Then, after I've activated a different
document, I run Macro 2, which accesses the variable MyDocFullName
from the function and sticks it into a line of code:

Documents(MyDocFullName).Activate

Larry




Larry wrote:
The purpose of this is to be able to activate this document by a
single command from another document. How would putting a static
variable within the module enable me to do that?

So that you can better understand what I'm doing here, here is the
second macro, by which I activate the first document (the one
whose name has been made into an AutoText entry by the first
macro) from another document. What would be the equivalent of
this using a variable instead of an AutoText entry?

Sub PrevDocActivate()

' Open (or activate) the document whose name (or fullname) has
been made into an
' AutoText entry.

' Uses Activate method if document is open, and Open method is
document is closed.

'Application.ScreenUpdating = False

Dim sDoc As Document
Dim PrevDocName As String
PrevDocName =
NormalTemplate.AutoTextEntries("MyDocFullName").Va lue 'Instead of
opening in all cases, do a For Each statement. For Each sDoc In
Documents If sDoc.FullName = PrevDocName Then
myFlag1 = True
Exit For
End If
Next
If myFlag1 = True Then

'DocFullNameStore

Documents(PrevDocName).Activate
Else
Documents.Open (PrevDocName)
End If

End Sub



Jezebel wrote:
Storing the name as a DocumentProperty or DocVariable would be
simpler; but if the name needs to be retained only for the
current session, why not simply put it into a static variable
within your VBA module?


"Larry" wrote in message
...

This macro works fine. It temporarily Inserts Fullname of the
active document into the document and makes that string an
AutoText entry called MyDocName, which is used later by
another macro to reactivate this document from another
document. This enables me to return instantly to this
document without having to open the Window menu or scroll
through the open documents. But I wonder if there is a more
efficient way of doing it, so that the active document's
FullName doesn't actually have to be inserted into the
document as a range, but rather the FullName becomes an
AutoText entry in one step. It seems that would make the
macro a little faster.

Any ideas? Thanks.
Larry
.

Sub DocFullNameStore()

Application.ScreenUpdating = False
Dim X As Long, Y As Long
Dim r As Range

X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.FullName
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocFullName",
Range:=r r.Delete

End Sub



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple word question rvance New Users 8 February 1st 05 02:16 AM
Autotext exclusive to a New Document Template I Create in Word 200 KM1 Microsoft Word Help 2 January 23rd 05 04:03 AM
auto current date entry in your document SDecou Microsoft Word Help 1 December 30th 04 10:47 PM
Inserting a hyperlink - Place in this document rhewell Microsoft Word Help 3 December 14th 04 03:49 AM
Using Hyperlinks in Mail Merge IF...THEN...ELSE Statements Mark V Mailmerge 8 November 30th 04 01:31 PM


All times are GMT +1. The time now is 10:49 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"