Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

storing info about current document to use later, when document is inactive

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry - 27 Nov 2004 23:03 GMT
How do you store information about the currently active document in a
macro or function, in order to access it later?

For example, I want to store the name of the current document, so that I
can run that name later, when a different document is active.

I know about storing information about a document in settings.text, and
then accessing it later, as below.  I just wondered if there was a way
to do the same thing completely within Word.

Selection.Font.name = System.PrivateProfileString("C:\Settings.Txt", _
   "MacroSettings", "Font")

Thanks,
Larry
Greg Maxey - 27 Nov 2004 23:18 GMT
Larry,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10/html/wo
howstoringvalues.asp


Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> How do you store information about the currently active document in a
> macro or function, in order to access it later?
[quoted text clipped - 11 lines]
> Thanks,
> Larry
Larry - 28 Nov 2004 04:22 GMT
Thanks for that reference.  I ended up using the AutoText method.  I was
having trouble making the Settings.txt method work with this one, I
don't know why.

Larry

> Larry,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10
/html/wohowstoringvalues.asp

> > How do you store information about the currently active document in
> > a macro or function, in order to access it later?
[quoted text clipped - 12 lines]
> > Thanks,
> > Larry
Larry - 28 Nov 2004 05:11 GMT
Here's what I did.  The first macro creates an AutoText entry with the
name of the active document. Then, after I've activated another
document, and want to return to the first, I run the second macro which
takes me back to the first document.

The reason I wanted this was, often I have a bunch of documents open,
I'm working on one main document, then going to some other document, and
then I either have to cycle through the documents to get back to the
main document, or else open the Window menu to look for the window
number of the main document and press that.  I wanted something that
would be automatically and in one step take me back to the document I
was working on.

Sub DocNameStore()

Application.ScreenUpdating = False
ActiveWindow.SplitVertical = 50
Selection.EndKey wdStory
Selection.InsertAfter ActiveDocument.Name
NormalTemplate.AutoTextEntries.Add Name:="MyDocName",
Range:=Selection.Range
Selection.TypeBackspace
ActiveWindow.SplitVertical = 100

End Sub

Sub PrevDocActivate()

Dim PrevDocName As String
PrevDocName = NormalTemplate.AutoTextEntries("MyDocName").Value
Documents(PrevDocName).Activate

End Sub

> Thanks for that reference.  I ended up using the AutoText method.  I
> was having trouble making the Settings.txt method work with this one,
[quoted text clipped - 3 lines]
>
> > Larry,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10
> /html/wohowstoringvalues.asp
> >
[quoted text clipped - 16 lines]
> > > Thanks,
> > > Larry
Larry - 28 Nov 2004 15:14 GMT
This is better.  Now the operation has no effect on the on-screen
appearance of the document.

Sub DocNameStore()

Dim X As Long, Y As Long
Dim r As Range
X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.Name
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocName", Range:=r
r.Delete

End Sub

> Here's what I did.  The first macro creates an AutoText entry with the
> name of the active document. Then, after I've activated another
[quoted text clipped - 37 lines]
> >
> > > Larry,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10
> > /html/wohowstoringvalues.asp
> > >
[quoted text clipped - 16 lines]
> > > > Thanks,
> > > > Larry
Tony - 02 Dec 2004 15:25 GMT
You can also use ProfileString (storing in registry) to
store the information e.g.

System.ProfileString("SubkeyName", "EntryName") = "Value"
MsgBox System.ProfileString("SubkeyName", "EntryName")

or store the information in normal.dot as a document
variable e.g.

Sub Test000()
  ScreenUpdating = False
 
  With NormalTemplate.OpenAsDocument
      .Variables.Add Name:="UserName",
Value:=Application.UserName
      .Close SaveChanges:=wdSaveChanges
  End With

  ScreenUpdating = True
End Sub

Grtz, Tony
>-----Original Message-----
>
[quoted text clipped - 79 lines]
>
>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.