Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 18 Mar 2008 16:04:10 +0100,    group: microsoft.public.word.vba.addins        back       


Get text-content out of AddIn   
Hello!

Is there a way to get the text out of a Word-AddIn?

As a Word-AddIn is basically a template (*.dot) it can not only contain 
code, modules, forms, etc. but also some text-content.
This text is only visible during design-time and can be edited just like the 
text of any other Word-document.

Now I´d like to store some lengthy strings (like help-texts) in there and 
read them on runtime to init the AddIn´s GUI with it.

As long as I am in design-mode the AddIn is opened like any other document:
- It is part of the Documents-collection.
- I can access its text-content like this:
     MyString = Word.Documents("MyAddIn.dot").Content.Text

But when the AddIn is loaded via Word´s AddIn-mechanism (e. g. automatically 
on Word-startup) it´s an AddIn.
- Now it is part of the AddIns-collection.
- The following command will *fail*:
     MyString = Word.AddIns("MyAddIn.dot").Content.Text

An AddIn-object seemingly doesn´t have properties like "Content" or "Text" 
any more :-(

And yet the text *is* still there.
It isn´t "compiled away" or something like that.
When I open the AddIn as Document again it´s still there, can be edited, 
copied, acces via code, ...

-> Do you know a way to get the text-content from a loaded AddIn on runtime?

Many thanks in Advance!
Harald Dehner
date: Tue, 18 Mar 2008 16:04:10 +0100   author:   Norberg xyz@xyz

Re: Get text-content out of AddIn   
"Norberg" <xyz@xyz> wrote in message 
news:%23oWWRhQiIHA.5280@TK2MSFTNGP02.phx.gbl...
> Hello!
>
> Is there a way to get the text out of a Word-AddIn?
>
> As a Word-AddIn is basically a template (*.dot) it can not only contain 
> code, modules, forms, etc. but also some text-content.
> This text is only visible during design-time and can be edited just like 
> the text of any other Word-document.
>
> Now I´d like to store some lengthy strings (like help-texts) in there and 
> read them on runtime to init the AddIn´s GUI with it.
>
> As long as I am in design-mode the AddIn is opened like any other 
> document:
> - It is part of the Documents-collection.
> - I can access its text-content like this:
>     MyString = Word.Documents("MyAddIn.dot").Content.Text
>
> But when the AddIn is loaded via Word´s AddIn-mechanism (e. g. 
> automatically on Word-startup) it´s an AddIn.
> - Now it is part of the AddIns-collection.
> - The following command will *fail*:
>     MyString = Word.AddIns("MyAddIn.dot").Content.Text
>
> An AddIn-object seemingly doesn´t have properties like "Content" or "Text" 
> any more :-(
>
> And yet the text *is* still there.
> It isn´t "compiled away" or something like that.
> When I open the AddIn as Document again it´s still there, can be edited, 
> copied, acces via code, ...
>
> -> Do you know a way to get the text-content from a loaded AddIn on 
> runtime?
>

Hi Harold

First of all, no you can't get text from an add-in the way you described.

There are various options available for you. Which will suit you best I 
don't know, which is why I'm going to list a few.

1. AutoText entries can be stored in an add-in and accessed in the normal 
way and inserted into a document as either plain or formatted text.

2. You can access both the CustomDocumentProperties and Variables 
collections of the add-in, and extract text from there

3. You could create a separate text file to be distributed with your add-in, 
perhaps an INI file. Use Karl Peterson's library to access INI files, go 
here to download it. http://vb.mvps.org/samples/project.asp?id=kpIni

-- 
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
date: Tue, 18 Mar 2008 15:34:07 -0000   author:   Jonathan West

Re: Get text-content out of AddIn   
Iterate the addin collection to get the full path of your addin, or if
you already have it then you can open it directly (which adds it to
the Documents collection) to get at its text.  You can also open it
invisibly (ie it is not visible via the UI --not recommended)


However I would not recommend this approach.


Jonathan's suggestions I think are better solutions.

Cheers
TonyS.
date: Sun, 23 Mar 2008 18:05:12 -0700 (PDT)   author:   Tony Strazzeri

Re: Get text-content out of AddIn   
Many thanks!
Sorry for the delay (I was quite busy on another project).

Your suggestions are all very interesting but don?t really apply to my 
problem.

I just thought of the "text-content" of an AddIn as an easy yet 
comfortable way of editing, storing and transporting lengthy strings 
within the AddIn itself :-(

-> Using AutoText or CustomDocumentProperties would spoil the ability to 
easily edit those texts.

-> I?m afraid additional (ini-)files are out of the question because one 
of my given restrictions is that one AddIn has to consist of one single 
file.

-> Opening the .dot-file hidden in Word could be a solution but I am 
afraid this could cause yet more problems like delays, access-rights and 
so on.


I did try yet another way in the meantime:
I referenced the VBProject itself hoping I could access it?s "This 
Document"-Component.
Didn?t work.
While loaded an AddIn?s project is protected.
Unprotecting it on runtime would include sendkeys-hacks that I really 
disapprove of.

Well thanks a lot & please post if you run across another solution.

Best regards!
Harald Dehner

P.S. Please don?t mind the different names - I inadvertedly used a 
colleagues account the last time.





Jonathan West schrieb:
> "Norberg" <xyz@xyz> wrote in message 
> news:%23oWWRhQiIHA.5280@TK2MSFTNGP02.phx.gbl...
>> Hello!
>>
>> Is there a way to get the text out of a Word-AddIn?
>>
>> As a Word-AddIn is basically a template (*.dot) it can not only contain 
>> code, modules, forms, etc. but also some text-content.
>> This text is only visible during design-time and can be edited just like 
>> the text of any other Word-document.
>>
>> Now I´d like to store some lengthy strings (like help-texts) in there and 
>> read them on runtime to init the AddIn´s GUI with it.
>>
>> As long as I am in design-mode the AddIn is opened like any other 
>> document:
>> - It is part of the Documents-collection.
>> - I can access its text-content like this:
>>     MyString = Word.Documents("MyAddIn.dot").Content.Text
>>
>> But when the AddIn is loaded via Word´s AddIn-mechanism (e. g. 
>> automatically on Word-startup) it´s an AddIn.
>> - Now it is part of the AddIns-collection.
>> - The following command will *fail*:
>>     MyString = Word.AddIns("MyAddIn.dot").Content.Text
>>
>> An AddIn-object seemingly doesn´t have properties like "Content" or "Text" 
>> any more :-(
>>
>> And yet the text *is* still there.
>> It isn´t "compiled away" or something like that.
>> When I open the AddIn as Document again it´s still there, can be edited, 
>> copied, acces via code, ...
>>
>> -> Do you know a way to get the text-content from a loaded AddIn on 
>> runtime?
>>
> 
> Hi Harold
> 
> First of all, no you can't get text from an add-in the way you described.
> 
> There are various options available for you. Which will suit you best I 
> don't know, which is why I'm going to list a few.
> 
> 1. AutoText entries can be stored in an add-in and accessed in the normal 
> way and inserted into a document as either plain or formatted text.
> 
> 2. You can access both the CustomDocumentProperties and Variables 
> collections of the add-in, and extract text from there
> 
> 3. You could create a separate text file to be distributed with your add-in, 
> perhaps an INI file. Use Karl Peterson's library to access INI files, go 
> here to download it. http://vb.mvps.org/samples/project.asp?id=kpIni
>
date: Thu, 27 Mar 2008 16:01:54 +0100   author:   Harald Dehner

Re: Get text-content out of AddIn   
“An AddIn-object seemingly doesn´t have properties like "Content" or "Text"

No, it does not.

“Do you know a way to get the text-content from a loaded AddIn on runtime?”

If a .dot file is loaded as an add-in, it is NOT loaded as a document.
Therefore:

1.  no document text content is available
2.  the project is unviewable

You can only get text from:

1.   a document file that is open (and an add-in is not)
2.   AutoText entries
3.   document properties or variables

These have been mentioned.

You can get the text content of an AutoText (say myTest in Normal.dot) with:

MsgBox NormalTemplate.AutoTextEntries("myTest").Value

So this could be a way of doing:

“Now I´d like to store some lengthy strings (like help-texts) in there and 
read them on runtime to init the AddIn´s GUI with it.”

AutoText entries can do that.

I just thought of the "text-content" of an AddIn as an easy yet comfortable
way of editing, storing and transporting lengthy strings within the AddIn
itself

AutoText entries can do that.

However, you also mention “edit”:  

“Using AutoText or CustomDocumentProperties would spoil the ability to 
easily edit those texts.”

That is whole different thing.  It can be done,you can change the value of an
Autotext entry.  Say you have an AutoText entry (myTest) that is the text:

“This is some AutoText…ummmm, text.”


MsgBox NormalTemplate.AutoTextEntries("myTest").Value
   ‘ displays “This is some AutoText…ummmm, text.”

NormalTemplate.AutoTextEntries("myTest").Value = _
   "Yadda yadda"

MsgBox NormalTemplate.AutoTextEntries("myTest").Value
   ‘ displays “Yadda yadda”

If you want to change it – not just REPLACE it like the code above, you would
have to put the Value in as a string, manipulate the string, then rewrite the
Value.

However, WHY would users need to edit it?  I can understand you (as the
developer) editing content, but if these are supposed to be help text, or
initializing text – “read them on runtime to init the AddIn´s GUI with it.” –
WHY do you need run-time editing?


Harald Dehner wrote:
>Many thanks!
>Sorry for the delay (I was quite busy on another project).
>
>Your suggestions are all very interesting but don?t really apply to my 
>problem.
>
>I just thought of the "text-content" of an AddIn as an easy yet 
>comfortable way of editing, storing and transporting lengthy strings 
>within the AddIn itself :-(
>
>-> Using AutoText or CustomDocumentProperties would spoil the ability to 
>easily edit those texts.
>
>-> I?m afraid additional (ini-)files are out of the question because one 
>of my given restrictions is that one AddIn has to consist of one single 
>file.
>
>-> Opening the .dot-file hidden in Word could be a solution but I am 
>afraid this could cause yet more problems like delays, access-rights and 
>so on.
>
>I did try yet another way in the meantime:
>I referenced the VBProject itself hoping I could access it?s "This 
>Document"-Component.
>Didn?t work.
>While loaded an AddIn?s project is protected.
>Unprotecting it on runtime would include sendkeys-hacks that I really 
>disapprove of.
>
>Well thanks a lot & please post if you run across another solution.
>
>Best regards!
>Harald Dehner
>
>P.S. Please don?t mind the different names - I inadvertedly used a 
>colleagues account the last time.
>
>Jonathan West schrieb:
>>> Hello!
>>>
>[quoted text clipped - 47 lines]
>> perhaps an INI file. Use Karl Peterson's library to access INI files, go 
>> here to download it. http://vb.mvps.org/samples/project.asp?id=kpIni

-- 
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200803/1
date: Thu, 27 Mar 2008 18:13:59 GMT   author:   fumei via OfficeKB.com u37563@uwe

Re: Get text-content out of AddIn   
I would like to add that you can use AutoText entries as Help messages very
easily for controls on a userform.  You mention the Add-in GUI.  I assume you
mean it has a userform.

For example;

A textbox whose purpose is to get a client case ID.

Above the textbox is a label, and the Caption property is:

Client case ID - Click here for Help

This both identifies what the textbox is for, AND can display more detailed
Help on it.  How?  By using the _Click event of the label.  Say the label is
named lblCaseID.  Its "Help" text is an AutoText entry named CaseIDHelp.

Private Sub lblCaseID_Click()
MsgBox NormalTemplate.AutoTextEntries("CaseID").Value
End Sub

Voila!  User clicks "Client case ID - Click here for Help" and they get a
message with the text content of the AutoText CaseID.

Or it could be a wee button beside a control with a caption "Help".



fumei wrote:
>“An AddIn-object seemingly doesn´t have properties like "Content" or "Text"
>
>No, it does not.
>
>“Do you know a way to get the text-content from a loaded AddIn on runtime?”
>
>If a .dot file is loaded as an add-in, it is NOT loaded as a document.
>Therefore:
>
>1.  no document text content is available
>2.  the project is unviewable
>
>You can only get text from:
>
>1.   a document file that is open (and an add-in is not)
>2.   AutoText entries
>3.   document properties or variables
>
>These have been mentioned.
>
>You can get the text content of an AutoText (say myTest in Normal.dot) with:
>
>MsgBox NormalTemplate.AutoTextEntries("myTest").Value
>
>So this could be a way of doing:
>
>“Now I´d like to store some lengthy strings (like help-texts) in there and 
>read them on runtime to init the AddIn´s GUI with it.”
>
>AutoText entries can do that.
>
>I just thought of the "text-content" of an AddIn as an easy yet comfortable
>way of editing, storing and transporting lengthy strings within the AddIn
>itself
>
>AutoText entries can do that.
>
>However, you also mention “edit”:  
>
>“Using AutoText or CustomDocumentProperties would spoil the ability to 
>easily edit those texts.”
>
>That is whole different thing.  It can be done,you can change the value of an
>Autotext entry.  Say you have an AutoText entry (myTest) that is the text:
>
>“This is some AutoText…ummmm, text.”
>
>MsgBox NormalTemplate.AutoTextEntries("myTest").Value
>   ‘ displays “This is some AutoText…ummmm, text.”
>
>NormalTemplate.AutoTextEntries("myTest").Value = _
>   "Yadda yadda"
>
>MsgBox NormalTemplate.AutoTextEntries("myTest").Value
>   ‘ displays “Yadda yadda”
>
>If you want to change it – not just REPLACE it like the code above, you would
>have to put the Value in as a string, manipulate the string, then rewrite the
>Value.
>
>However, WHY would users need to edit it?  I can understand you (as the
>developer) editing content, but if these are supposed to be help text, or
>initializing text – “read them on runtime to init the AddIn´s GUI with it.” –
>WHY do you need run-time editing?
>
>>Many thanks!
>>Sorry for the delay (I was quite busy on another project).
>[quoted text clipped - 39 lines]
>>> perhaps an INI file. Use Karl Peterson's library to access INI files, go 
>>> here to download it. http://vb.mvps.org/samples/project.asp?id=kpIni

-- 
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200803/1
date: Thu, 27 Mar 2008 19:01:57 GMT   author:   fumei via OfficeKB.com u37563@uwe

Re: Get text-content out of AddIn   
Ooops, that should be:

Private Sub lblCaseID_Click()
MsgBox NormalTemplate.AutoTextEntries("CaseIDHelp").Value
End Sub


forgot the Help!

fumei wrote:
>I would like to add that you can use AutoText entries as Help messages very
>easily for controls on a userform.  You mention the Add-in GUI.  I assume you
>mean it has a userform.
>
>For example;
>
>A textbox whose purpose is to get a client case ID.
>
>Above the textbox is a label, and the Caption property is:
>
>Client case ID - Click here for Help
>
>This both identifies what the textbox is for, AND can display more detailed
>Help on it.  How?  By using the _Click event of the label.  Say the label is
>named lblCaseID.  Its "Help" text is an AutoText entry named CaseIDHelp.
>
>Private Sub lblCaseID_Click()
>MsgBox NormalTemplate.AutoTextEntries("CaseID").Value
>End Sub
>
>Voila!  User clicks "Client case ID - Click here for Help" and they get a
>message with the text content of the AutoText CaseID.
>
>Or it could be a wee button beside a control with a caption "Help".
>
>>“An AddIn-object seemingly doesn´t have properties like "Content" or "Text"
>>
>[quoted text clipped - 66 lines]
>>>> perhaps an INI file. Use Karl Peterson's library to access INI files, go 
>>>> here to download it. http://vb.mvps.org/samples/project.asp?id=kpIni

-- 
Message posted via http://www.officekb.com
date: Thu, 27 Mar 2008 19:03:08 GMT   author:   fumei via OfficeKB.com u37563@uwe

Re: Get text-content out of AddIn   
fumei via OfficeKB.com schrieb:
> (...)
> However, WHY would users need to edit it?  I can understand you (as the
> developer) editing content, but if these are supposed to be help text, or
> initializing text – “read them on runtime to init the AddIn´s GUI with it.” –
> WHY do you need run-time editing?

I don´t need runtime editing. Just during development.

Take the version-history as an example:
As I am working with Word open on one Screen and the VBE on the other 
screen I eventually thought it to be quite comfortable to type the 
history directly into the "sheet" of the already opened AddIn.

-> very neat!
History is always present and easy to edit during coding :-)

I started to include a ToDo-list and some other stuff there as well.

All was well.
Until at one point I thought it to be an even better idea to show some 
of these already-there texts to the user of my tool via its GUI (= its 
form).

So I wrote some methods to locate the respective text-passages and 
assign them to some textboxes of the form.

All was well, again.
Until I had to realize that this didn´t work as soon as the AddIn wasn´t 
opened as document (for developing) but as AddIn...


Storing the necessary texts as AutoText would make it necessary to edit 
those texts via Words AutoText-Editor (Menu -> Extras -> andsoon...)
And no matter how easy this may be - it´s far from being as easy as just 
typing plain text into the sheet whenever you fell like it :-)


Nevertheless...
I could try and write some sort of converter that I run at end of one 
development-session that stores my text-passages into AutoTexts...
I´ll give it a try!!


Thanks a lot!
Harald Dehner
date: Fri, 28 Mar 2008 15:23:12 +0100   author:   Harald Dehner

Re: Get text-content out of AddIn   
"Harald Dehner"  wrote in message 
news:eFtvIrBkIHA.5280@TK2MSFTNGP02.phx.gbl...
> Many thanks!
> Sorry for the delay (I was quite busy on another project).
>
> Your suggestions are all very interesting but don?t really apply to my 
> problem.
>
> I just thought of the "text-content" of an AddIn as an easy yet 
> comfortable way of editing, storing and transporting lengthy strings 
> within the AddIn itself :-(
>
> -> Using AutoText or CustomDocumentProperties would spoil the ability to 
> easily edit those texts.

Not really. You can edit the text in the body, select it all, and then put 
it into a property using the following line

ActiveDocument.CustomDocumentProperties("My settings") = Selection.Text

or if using a document variable

ActiveDocument.Variables("My settings") = Selection.Text

>
> -> I?m afraid additional (ini-)files are out of the question because one 
> of my given restrictions is that one AddIn has to consist of one single 
> file.

In that case it's not appropriate to you. I didn't know that at the time I 
made the suggestion.

>
> -> Opening the .dot-file hidden in Word could be a solution but I am 
> afraid this could cause yet more problems like delays, access-rights and 
> so on.

I rather suspect so, and I would not recommend this approach.

>
>
> I did try yet another way in the meantime:
> I referenced the VBProject itself hoping I could access it?s "This 
> Document"-Component.
> Didn?t work.
> While loaded an AddIn?s project is protected.
> Unprotecting it on runtime would include sendkeys-hacks that I really 
> disapprove of.

Even if you manage to unprotect it, programmatic access to the VB project is 
dependent on the individual user's security settings in Tools, Macro, 
Security, specifically whether the "Trust access to the Visual Basic 
Project" is checked. By default it is not. You can't change this from within 
VBA.

>
> Well thanks a lot & please post if you run across another solution.
>
> Best regards!
> Harald Dehner
>
> P.S. Please don?t mind the different names - I inadvertedly used a 
> colleagues account the last time.

That's OK. It feels a bit witless replying to some obviously false moniker 
such as "MadDog", but a simple mistake over use of accounts is no big issue, 
though your colleague may not be overly happy at the amount of spam his 
account is likely to receive now his unmodified email address have been 
published.


-- 
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
date: Wed, 2 Apr 2008 13:45:13 +0100   author:   Jonathan West

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us