|
|
|
date: Tue, 18 Mar 2008 16:04:10 +0100,
group: microsoft.public.word.vba.addins
back
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
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
"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
|
|