Getting the list of Autocorrect enties in word

  • Thread starter Thread starter nagar
  • Start date Start date
N

nagar

I need to get the list of Autocorrect entries in word. Is there a way
to do it without connecting to Word? Is the list saved somewhere?
If I need to connect to Word, how can I detect if it's installed on
the user machine?
Thanks.
Andrea
 
Hello Andrea,

From your post, my understanding on this issue is: you want to get the
auto-correct entries in Word. If I'm off base, please feel free to let me
know.

If you are using Office 2003/2002, please refer to the kb article:
http://support.microsoft.com/kb/826147 or
http://support.microsoft.com/kb/269006/EN-US/. Office 2002/2003 has a
'AutoCorrect Utility' in C:\Program Files\Microsoft
Office\Office\Macros\SUPPORT.DOT, which can help you export the
auto-correct entries. In Word 2000, the utility is located in C:\Program
Files\Microsoft Office\Office\Samples\Macros9.dot (see:
http://support.microsoft.com/kb/207748/EN-US/). As to Office Word 97 or 95,
please refer to http://support.microsoft.com/kb/186237/EN-US/ or
http://support.microsoft.com/default.aspx?scid=kb;en-us;135778&Product=wrd97
 
Thanks Jialiang.
I actually need to process the entries in my C# application.

I added a reference to Microsoft Word 12.0 Object Libary and used this
code to enumerate the autocorrections

Microsoft.Office.Interop.Word.Application word= new Application();
AutoCorrect ac = word.AutoCorrect;

foreach (AutoCorrectEntry ae in ac.Entries) {
string abb = ae.Name;
string body = ae.Value;
}



My questions are:

1. I've attached to MS Word 2007. What should I do to get the
autocorrect from Office 2003?
2. What files should I distribute with my application. I saw VS2005
added a reference to Microsoft.Office.Core,
Microsoft.Office.Interop.Word and VBIDE.


Thanks
Andrea
 
Hello Andrea,

Thank you for the quick reply. I notice that you once posted a same issue
in the queue: microsoft.public.word.programming on 2007-8-7
(http://msdn.microsoft.com/newsgroups/managed/Default.aspx?dg=microsoft.publ
ic.word.programming&mid=5ea81601-1a30-4aec-ab55-a0c6a8dc89fb)
microsoft.public.word.programming is not a managed queue, thus we were not
notified about that post and we did not jump in. The following link refers
to a list of all the managed queues where the replies are ensured.
http://msdn2.microsoft.com/en-us/subscriptions/aa974230.aspx
1. I've attached to MS Word 2007. What should I do to get the autocorrect
from Office 2003?
In the post dated on 2007-8-7, I notice that your actual need is to export
the auto-correct entries of Office Word 2003 into a text file with a C#
program. If I'm off base, please feel free to let me know.
First, we need to find a computer installed with Office 2003 Word and
Office 2003 PIA. Add the reference to Microsoft Word 11.0 Object Library in
your C# project.
Secondly, try the following C# code list to export the Word 2003
autocorrect entries into a txt file:
using System;
using System.Collections.Generic;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
object missing = Type.Missing;
Word.Application application = new Word.Application();
int total = GetAutoCorrectEntries(application);
application.Quit(ref missing, ref missing, ref missing);
}
public static int GetAutoCorrectEntries(Word.Application
application)
{
StreamWriter writer = new StreamWriter(@"D:\entries.txt");
int TotalACEntries = application.AutoCorrect.Entries.Count;
string entry;
for (int x = 1; x <= TotalACEntries; x++)
{
object index = (object)x;
entry = application.AutoCorrect.Entries.get_Item(ref
index).Name;
entry += "\t";
entry += application.AutoCorrect.Entries.get_Item(ref
index).Value;
writer.WriteLine(entry);
}
writer.Close();
return TotalACEntries;
}
}
}
The code above will help you create a txt file containing all entries:
D:\entries.txt.
The format of the pairs is : name\tvalue. For instance, abbout about
Therefore, it is quite easy to parse this entry list of Word 2003 into a
hash table or dictionary from the txt file when you are using Office 2007.
StreamReader reader = new StreamReader(@"D:\entries.txt");
string line = reader.ReadLine();
Hashtable entries = new Hashtable();
while (line != null)
{
string[] parts = line.Split('\t');
entries.Add(parts[0], parts[1]);
line = reader.ReadLine();
}
reader.Close();
2. What files should I distribute with my application. I saw VS2005 added
a reference to Microsoft.Office.Core, Microsoft.Office.Interop.Word and
VBIDE.
They are components of Office PIA.
If you are using Office XP, please refer to the section "Distributing
Solutions That Reply On the Office XP PIAs" of the following MSDN article:
http://msdn2.microsoft.com/en-us/library/aa163987(office.10).aspx

if you are using Office 2003, The only supported redistribution method is
to use the Office 2003 Update: Redistributable Primary Interop Assemblies
http://www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-
8ba0-d36d67e0f4ad&displaylang=en. According to the Readme shipped with the
package, we have the following choice. To install the Office 2003 Primary
Interop Assemblies, follow one of the following methods:
1 Double-click the O2003PIA.msi file
2 Execute "msiexec.exe /i O2003pia.msi", or
3 Wrap the O2003pia.msi in another setup package through Visual Studio or
other Windows Installer aware setup editor.
Please note that the Office 2003 Primary Interop Assemblies setup does not
support the /a or /j options for MsiExec.
For the third option, I think you may try to take a look at the link below.
How To Create a Nested .msi Package http://support.microsoft.com/?id=306439

Also we have specified queue about setup project, if you still have any
concern ,please feel free to post there, so that experienced expert will
give you more idea.
microsoft.public.platformsdk.msi or microsoft.public.vstudio.setup

If you have any other concern or need anything else, please feel free to
let me know.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Jialang,

I tried your code and it works on both Word 2003 and Word 2007.
Before I tried the Office12 object model which offers the ability to
detect if the Autotext was in RichText format. Is there a way to
detect it in Office 2003?
Thanks,
Andrea


Hello Andrea,

Thank you for the quick reply. I notice that you once posted a same issue
in the queue: microsoft.public.word.programming on 2007-8-7
(http://msdn.microsoft.com/newsgroups/managed/Default.aspx?dg=microsoft.publ
ic.word.programming&mid=5ea81601-1a30-4aec-ab55-a0c6a8dc89fb)
microsoft.public.word.programming is not a managed queue, thus we were not
notified about that post and we did not jump in. The following link refers
to a list of all the managed queues where the replies are ensured.
http://msdn2.microsoft.com/en-us/subscriptions/aa974230.aspx
1. I've attached to MS Word 2007. What should I do to get the autocorrect
from Office 2003?
In the post dated on 2007-8-7, I notice that your actual need is to export
the auto-correct entries of Office Word 2003 into a text file with a C#
program. If I'm off base, please feel free to let me know.
First, we need to find a computer installed with Office 2003 Word and
Office 2003 PIA. Add the reference to Microsoft Word 11.0 Object Library in
your C# project.
Secondly, try the following C# code list to export the Word 2003
autocorrect entries into a txt file:
using System;
using System.Collections.Generic;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
object missing = Type.Missing;
Word.Application application = new Word.Application();
int total = GetAutoCorrectEntries(application);
application.Quit(ref missing, ref missing, ref missing);
}
public static int GetAutoCorrectEntries(Word.Application
application)
{
StreamWriter writer = new StreamWriter(@"D:\entries.txt");
int TotalACEntries = application.AutoCorrect.Entries.Count;
string entry;
for (int x = 1; x <= TotalACEntries; x++)
{
object index = (object)x;
entry = application.AutoCorrect.Entries.get_Item(ref
index).Name;
entry += "\t";
entry += application.AutoCorrect.Entries.get_Item(ref
index).Value;
writer.WriteLine(entry);
}
writer.Close();
return TotalACEntries;
}
}
}
The code above will help you create a txt file containing all entries:
D:\entries.txt.
The format of the pairs is : name\tvalue. For instance, abbout about
Therefore, it is quite easy to parse this entry list of Word 2003 into a
hash table or dictionary from the txt file when you are using Office 2007.
StreamReader reader = new StreamReader(@"D:\entries.txt");
string line = reader.ReadLine();
Hashtable entries = new Hashtable();
while (line != null)
{
string[] parts = line.Split('\t');
entries.Add(parts[0], parts[1]);
line = reader.ReadLine();
}
reader.Close();
2. What files should I distribute with my application. I saw VS2005 added
a reference to Microsoft.Office.Core, Microsoft.Office.Interop.Word and
VBIDE.
They are components of Office PIA.
If you are using Office XP, please refer to the section "Distributing
Solutions That Reply On the Office XP PIAs" of the following MSDN article:
http://msdn2.microsoft.com/en-us/library/aa163987(office.10).aspx

if you are using Office 2003, The only supported redistribution method is
to use the Office 2003 Update: Redistributable Primary Interop Assemblies
http://www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-
8ba0-d36d67e0f4ad&displaylang=en. According to the Readme shipped with the
package, we have the following choice. To install the Office 2003 Primary
Interop Assemblies, follow one of the following methods:
1 Double-click the O2003PIA.msi file
2 Execute "msiexec.exe /i O2003pia.msi", or
3 Wrap the O2003pia.msi in another setup package through Visual Studio or
other Windows Installer aware setup editor.
Please note that the Office 2003 Primary Interop Assemblies setup does not
support the /a or /j options for MsiExec.
For the third option, I think you may try to take a look at the link below.
How To Create a Nested .msi Package http://support.microsoft.com/?id=306439

Also we have specified queue about setup project, if you still have any
concern ,please feel free to post there, so that experienced expert will
give you more idea.
microsoft.public.platformsdk.msi or microsoft.public.vstudio.setup

If you have any other concern or need anything else, please feel free to
let me know.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Andrea,

Yes, Office 2003 can also detect rich text format by using the property
'RichText' of AutoCorrectEntry object. For instance:

if (application.AutoCorrect.Entries.get_Item(ref index).RichText)
application.AutoCorrect.Entries.get_Item(ref
index).Apply(application.Selection.Range);

Both Office 2007 and Office 2003 support this property.

Please feel free to let me know if you have any other concern.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks.
One more thing. I noticed that if the entry is in RichTextFormat I get
an * symbol in the string (the Value property). Is there a way to get
properly formatted text?
Thanks,
Andrea
 
Hello Andrea,

AutoCorrectEntry.Value is invalid when the entry is in RichText format. But
the entry object provides a method 'Apply' which can replace a Word Range
with the value of the specified AutoCorrect entry.
http://msdn2.microsoft.com/es-es/library/microsoft.office.interop.word.autoc
orrectentry.apply(VS.80).aspx

Because .txt file does not support rich text format, the entries with rich
text cannot be exported to .txt. The following code listing demonstrate how
to export the entries into a Word document instead.
static void Main(string[] args)
{
object missing = Type.Missing;
object filename = @"d:\test.doc";
Word.Application application = new Word.Application();
application.ScreenUpdating = false;
application.DisplayAlerts =
Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
// create new document
Word.Document doc = application.Documents.Add(ref missing, ref
missing, ref missing, ref missing);

Program.GetAutoCorrectEntries(application);

doc.SaveAs(ref filename, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref
missing,
ref missing, ref missing, ref missing, ref missing, ref
missing,
ref missing, ref missing);
application.ScreenUpdating = true;
application.DisplayAlerts =
Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
application.Quit(ref missing, ref missing, ref missing);
}

public static int GetAutoCorrectEntries(Word.Application
application)
{
int TotalACEntries = application.AutoCorrect.Entries.Count;
string entry;
for (int x = 1; x <= TotalACEntries; x++)
{
object index = (object)x;

application.Selection.TypeText(application.AutoCorrect.Entries.get_Item(ref
index).Name + "\t");
if (application.AutoCorrect.Entries.get_Item(ref
index).RichText)
application.AutoCorrect.Entries.get_Item(ref
index).Apply(application.Selection.Range);
else

application.Selection.TypeText(application.AutoCorrect.Entries.get_Item(ref
index).Value);

application.Selection.TypeText("\t");

application.Selection.TypeText(application.AutoCorrect.Entries.get_Item(ref
index).RichText.ToString());
application.Selection.TypeParagraph();
}
return TotalACEntries;
}

The above codes create a doc file in your d:\ directory. The entries are in
the form of: Name\tValue\tIsRichText where the last field indicates whether
it's a rich text entry or not.

In SUPPORT.dot (See my first reply), there is a lot of VBA functions that
do the same thing. For instance, there is a sub named btnBackup_click() to
import the entries. I'm actually just converting those VBA to C# here. You
may have a look at SUPPORT.dot and have a clearer picture of this process.

Please feel free to let me know if you have any other concern.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Andrea,

Would you mind letting me know the result of the suggestions? If you need
further assistance, feel free to let me know. I will be more than happy to
be of assistance.

Have a great day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top