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


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



Relevant Pages

  • Re: Using ActiveDocument when mutliple documents open
    ... Sub TestActiveDocument() ... cannot reliably identify the active document every time. ... has something to do with how Word 2007 handles its document windows. ... As I can replicate this problem with a one line macro ...
    (microsoft.public.word.vba.general)
  • Re: Require input in a cell before saving file
    ... or 2) Digitally sign and verify the macro as safe. ... Cancel As Boolean) ... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, ... ...and yet I still can save the file with cell E59 being empty. ...
    (microsoft.public.excel.misc)
  • Re: Table in a Form
    ... > Sub AddTimeRow() ... > ' Macro written 12/01/2003 by Charles Kyle Kenyon ... > Dim oTemplate As Template ...
    (microsoft.public.word.tables)
  • Re: How to capture Max cell value (High Water Mark)
    ... a look saving the value and initializing it on worksheet open. ... addressing whatever cell was active on the worksheet. ... Sub Test_Enable_Events ... I'm only using it on the same worksheet where the macro was created. ...
    (microsoft.public.excel)
  • Re: Insert a Field and assign to button
    ... ' AddTimeRow Macro ... Dim oTemplate As Template ... .CorrectInitialCaps = True ... Sub InsertRowAboveMe() ...
    (microsoft.public.word.vba.general)