Re: How to make doc's FullName into an AutoText entry without first inserting it into document
From: Larry (larry328_at_att.net)
Date: 02/01/05
- Next message: Larry: "Re: A period corruption in Normal.dot"
- Previous message: Vince: "Re: Search and Replace in String"
- In reply to: Jezebel: "Re: How to make doc's FullName into an AutoText entry without first inserting it into document"
- Next in thread: Jezebel: "Re: How to make doc's FullName into an AutoText entry without first inserting it into document"
- Reply: Jezebel: "Re: How to make doc's FullName into an AutoText entry without first inserting it into document"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 1 Feb 2005 00:58:36 -0500
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" <larry328@att.net> wrote in message
> news:eteZn58BFHA.3504@TK2MSFTNGP12.phx.gbl...
> > 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").Value '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" <larry328@att.net> wrote in message
> > > > news:e6PlHC0BFHA.3976@tk2msftngp13.phx.gbl...
> > > > >
> > > > > 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
- Next message: Larry: "Re: A period corruption in Normal.dot"
- Previous message: Vince: "Re: Search and Replace in String"
- In reply to: Jezebel: "Re: How to make doc's FullName into an AutoText entry without first inserting it into document"
- Next in thread: Jezebel: "Re: How to make doc's FullName into an AutoText entry without first inserting it into document"
- Reply: Jezebel: "Re: How to make doc's FullName into an AutoText entry without first inserting it into document"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|