The Code Cage - Microsoft Office help Free Microsoft Office Help for all Applications!  

To stop seeing these ads and get other benefits check This page!

Go Back   The Code Cage Forums > Newsgroups - Microsoft Topics > Newsgroup - Word Forum > Word VBA Programming
  Microsoft Office Chat Online now!


Word VBA Programming Post questions in this forum if they are related to using Microsoft Word VBA Programming, Macro's etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11th November 2008, 05:10 PM
DaveB
Newsgroup Contributor


My Top Tip Count:

 
Posts: n/a
Chats:
Default RE: Acronym macro - find and print in second file

------ Register to get rid of these "In Post" ads! ------


Thanks for making this macro public. I was looking for one that has this
type of functionality. But, I was hoping it would create the glossary in the
beginning of the document and to also create infotips for each instance of an
acronym's usage, such that, in the body of the document, the infotip pops up
with the definition from the glossary. [I suppose you could extend this idea
to centralize the glossary in one (or more) external documents by having the
macro prompt for the path to the external doc prior to performing its
function or leveraging a reference at the beginning of the document, to the
external glossary document. ]

I could not figure out how to create infotips easily (I am currently using
Office 2003. Does Office 2007 address this functional concern?).

"Lene Fredborg" wrote:

> Below you will find a macro that extracts all words consisting of three or
> more uppercase letters to a new document. I have added comments in the code
> that explains what is going on. You may want to add more code to adjust the
> layout of the table into which the acronyms are inserted. I just made the
> macro and tested it on a small test document and it seems to work correctly –
> however, you may want to adjust what it does.
>
>
> Sub ExtractAcronymsToNewDocument()
>
> 'Finds all words consisting of 3 or more uppercase letters
> 'in active document document and inserts the words
> 'in column 1 of a 3-column table in a new document
'Original Source: The Code Cage Forums http://www.thecodecage.com/forumz/word-vba-programming/28044-re-acronym-macro-find-print-second-file.html#post100587
> 'Each acronym is added only once
> 'Room for definition in column 2
> 'Page number of first occurrence is added in column 3
>
> Dim oDoc_Source As Document
> Dim oDoc_Target As Document
> Dim strListSep As String
> Dim strAcronym As String
> Dim oTable As Table
> Dim oRange As Range
> Dim n As Long
> Dim strAllFound As String 'use to keep track of foudnd
>
> 'Find the list separator from international settings
> 'In some countries it is comma, in other semicolon
> strListSep = Application.International(wdListSeparator)
>
> strAllFound = "#"
>
> Set oDoc_Source = ActiveDocument
> 'Create new document for acronyms
> Set oDoc_Target = Documents.Add
>
> With oDoc_Target
> 'Make sure document is empty
> .Range = ""
>
> 'Insert a table with room for acronym and definition
> Set oTable = .Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=3)
> With oTable
> 'Format the table a bit
> 'Insert headings
> .Cell(1, 1).Range.Text = "Acronym"
> .Cell(1, 2).Range.Text = "Definition"
> .Cell(1, 3).Range.Text = "Page"
> 'Set row as heading row
> .Rows(1).HeadingFormat = True
> .Rows(1).Range.Font.Bold = True
> .PreferredWidthType = wdPreferredWidthPercent
> .Columns(1).PreferredWidth = 20
> .Columns(2).PreferredWidth = 70
> .Columns(3).PreferredWidth = 10
> End With
> End With
>
> With oDoc_Source
> Set oRange = .Range
>
> n = 1 'used to count below
>
> With oRange.Find
> .Text = "<[A-Z]{3" & strListSep & "}>"
> .Forward = True
> .Wrap = wdFindStop
> .Format = False
> .MatchCase = True
> .MatchWildcards = True
> Do While .Execute
> 'Continue while found
> strAcronym = oRange
> 'Insert in target doc
>
> 'If strAcronym is already in strAllFound, do not add again
> If InStr(1, strAllFound, "#" & strAcronym & "#") = 0 Then
> 'Add new row in table from second acronym
> If n > 1 Then oTable.Rows.Add
> 'Was not found before
> strAllFound = strAllFound & strAcronym & "#"
>
> 'Insert in column 1 in oTable
> 'Compensate for heading row
> With oTable
> .Cell(n + 1, 1).Range.Text = strAcronym
> 'Insert page number in column 3
> .Cell(n + 1, 3).Range.Text =
> oRange.Information(wdActiveEndPageNumber)
> End With
>
> n = n + 1
> End If
>
> 'If acronym
> Loop
> End With
> End With
>
> 'Sort the acronyms alphabetically
> With Selection
> .Sort ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType _
> :=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending
>
> .HomeKey (wdStory)
> End With
>
> 'Clean up
> Set oDoc_Source = Nothing
> Set oDoc_Target = Nothing
> Set oTable = Nothing
>
> MsgBox "Finished extracting " & n - 1 & " acronymn(s) to a new document."
>
> End Sub
>
> --
> Regards
> Lene Fredborg - Microsoft MVP (Word)
> DocTools - Denmark
> www.thedoctools.com
> Document automation - add-ins, macros and templates for Microsoft Word
>
>
> "BHW" wrote:
>
> > Hi,
> >
> > Back in '02 Mark Tangard suggested this snippet to find macros.
> > With Selection.Find
> > .Text = "<[A-Z]{3,}>"
> > .Forward = True
> > .Wrap = wdFindStop
> > .Format = False
> > .MatchCase = True
> > .MatchWildcards = True
> > .Execute
> > End With
> >
> > Has anyone (or would anyone like to) used this to create a fuller
> > macro that reads through file 1, finds acronyms, and writes them and
> > the page number to file 2? Alternatively, has anyone written a macro
> > that finds the first use of an acronym and somehow checks that it is
> > indeed defined (and only defined once!) with that first use?
> >
> > Cheers, Bruce
> >

Reply to this post


Did you find this post helpful? Yes | No

The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!
  #2 (permalink)  
Old 11th November 2008, 07:37 PM
Lene Fredborg
Newsgroup Contributor


My Top Tip Count:

 
Posts: n/a
Chats:
Default RE: Acronym macro - find and print in second file

------ Register to get rid of these "In Post" ads! ------


I created the macro based on the question in the original post in this
thread. The macro could be adjusted to insert the table in the active
document instead. What you request is more complex - but actually, after I
created the acronym macro, I added something similar (maybe less advanced) to
my “macro idea list” (may be created some day when I find the time…).

For ideas on how you could create what you refer to as infotips, see this
thread:
http://groups.google.com/group/micro...addd74a327251b
'Original Source: The Code Cage Forums http://www.thecodecage.com/forumz/word-vba-programming/28044-re-acronym-macro-find-print-second-file.html#post100897

Word 2007 does not have any dedicated functionality for creating infotips.
The AutoTextList method described in the thread above can also be used in
Word 2007.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"DaveB" wrote:

> Thanks for making this macro public. I was looking for one that has this
> type of functionality. But, I was hoping it would create the glossary in the
> beginning of the document and to also create infotips for each instance of an
> acronym's usage, such that, in the body of the document, the infotip pops up
> with the definition from the glossary. [I suppose you could extend this idea
> to centralize the glossary in one (or more) external documents by having the
> macro prompt for the path to the external doc prior to performing its
> function or leveraging a reference at the beginning of the document, to the
> external glossary document. ]
>
> I could not figure out how to create infotips easily (I am currently using
> Office 2003. Does Office 2007 address this functional concern?).
>
> "Lene Fredborg" wrote:
>
> > Below you will find a macro that extracts all words consisting of three or
> > more uppercase letters to a new document. I have added comments in the code
> > that explains what is going on. You may want to add more code to adjust the
> > layout of the table into which the acronyms are inserted. I just made the
> > macro and tested it on a small test document and it seems to work correctly –
> > however, you may want to adjust what it does.
> >
> >
> > Sub ExtractAcronymsToNewDocument()
> >
> > 'Finds all words consisting of 3 or more uppercase letters
> > 'in active document document and inserts the words
> > 'in column 1 of a 3-column table in a new document
> > 'Each acronym is added only once
> > 'Room for definition in column 2
> > 'Page number of first occurrence is added in column 3
> >
> > Dim oDoc_Source As Document
> > Dim oDoc_Target As Document
> > Dim strListSep As String
> > Dim strAcronym As String
> > Dim oTable As Table
> > Dim oRange As Range
> > Dim n As Long
> > Dim strAllFound As String 'use to keep track of foudnd
> >
> > 'Find the list separator from international settings
> > 'In some countries it is comma, in other semicolon
> > strListSep = Application.International(wdListSeparator)
> >
> > strAllFound = "#"
> >
> > Set oDoc_Source = ActiveDocument
> > 'Create new document for acronyms
> > Set oDoc_Target = Documents.Add
> >
> > With oDoc_Target
> > 'Make sure document is empty
> > .Range = ""
> >
> > 'Insert a table with room for acronym and definition
> > Set oTable = .Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=3)
> > With oTable
> > 'Format the table a bit
> > 'Insert headings
> > .Cell(1, 1).Range.Text = "Acronym"
> > .Cell(1, 2).Range.Text = "Definition"
> > .Cell(1, 3).Range.Text = "Page"
> > 'Set row as heading row
> > .Rows(1).HeadingFormat = True
> > .Rows(1).Range.Font.Bold = True
> > .PreferredWidthType = wdPreferredWidthPercent
> > .Columns(1).PreferredWidth = 20
> > .Columns(2).PreferredWidth = 70
> > .Columns(3).PreferredWidth = 10
> > End With
> > End With
> >
> > With oDoc_Source
> > Set oRange = .Range
> >
> > n = 1 'used to count below
> >
> > With oRange.Find
> > .Text = "<[A-Z]{3" & strListSep & "}>"
> > .Forward = True
> > .Wrap = wdFindStop
> > .Format = False
> > .MatchCase = True
> > .MatchWildcards = True
> > Do While .Execute
> > 'Continue while found
> > strAcronym = oRange
> > 'Insert in target doc
> >
> > 'If strAcronym is already in strAllFound, do not add again
> > If InStr(1, strAllFound, "#" & strAcronym & "#") = 0 Then
> > 'Add new row in table from second acronym
> > If n > 1 Then oTable.Rows.Add
> > 'Was not found before
> > strAllFound = strAllFound & strAcronym & "#"
> >
> > 'Insert in column 1 in oTable
> > 'Compensate for heading row
> > With oTable
> > .Cell(n + 1, 1).Range.Text = strAcronym
> > 'Insert page number in column 3
> > .Cell(n + 1, 3).Range.Text =
> > oRange.Information(wdActiveEndPageNumber)
> > End With
> >
> > n = n + 1
> > End If
> >
> > 'If acronym
> > Loop
> > End With
> > End With
> >
> > 'Sort the acronyms alphabetically
> > With Selection
> > .Sort ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType _
> > :=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending
> >
> > .HomeKey (wdStory)
> > End With
> >
> > 'Clean up
> > Set oDoc_Source = Nothing
> > Set oDoc_Target = Nothing
> > Set oTable = Nothing
> >
> > MsgBox "Finished extracting " & n - 1 & " acronymn(s) to a new document."
> >
> > End Sub
> >
> > --
> > Regards
> > Lene Fredborg - Microsoft MVP (Word)
> > DocTools - Denmark
> > www.thedoctools.com
> > Document automation - add-ins, macros and templates for Microsoft Word
> >
> >
> > "BHW" wrote:
> >
> > > Hi,
> > >
> > > Back in '02 Mark Tangard suggested this snippet to find macros.
> > > With Selection.Find
> > > .Text = "<[A-Z]{3,}>"
> > > .Forward = True
> > > .Wrap = wdFindStop
> > > .Format = False
> > > .MatchCase = True
> > > .MatchWildcards = True
> > > .Execute
> > > End With
> > >
> > > Has anyone (or would anyone like to) used this to create a fuller
> > > macro that reads through file 1, finds acronyms, and writes them and
> > > the page number to file 2? Alternatively, has anyone written a macro
> > > that finds the first use of an acronym and somehow checks that it is
> > > indeed defined (and only defined once!) with that first use?
> > >
> > > Cheers, Bruce
> > >

Reply to this post


Did you find this post helpful? Yes | No
  #3 (permalink)  
Old 12th November 2008, 05:45 PM
Junior Member


My Top Tip Count: 0

 
Join Date: Nov 2008
Location: Columbus, USA
Posts: 1
Thanks to others: 0
Thanked 0 Times in 0 Posts
Chats: 0
Rep Power: 0
Karen is on a distinguished road
USA
Default Acronym macro-Karen

------ Register to get rid of these "In Post" ads! ------


Is there a way to generate the acronym definition in the second column of the table? The macro works great except for including the definition, which is a major part of the acronym list.
Reply to this post


Did you find this post helpful? Yes | No
The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!
Reply

Bookmarks

Tags
acronym, file, macro, print


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

The Code Cage Affilliates


To stop seeing these ads and get other benefits check This page!



All times are GMT +1. The time now is 08:15 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2
No part of this board may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application the represent