none
Store and Insert lines of text into any word document

    Question

  • Hi

    I want to be able to store lines of text (using a word addin) from a word document in a common file (for the time being it can be on my local machine) that can be inserted into any word document.

    I was reading up on SQL and XML and I had a feeling that I use SQL to do the database work and the XML can be this common file that stores all the lines of text. Am I right by using these technologies or is there an easier way. I see that you can create a simple txt file to do this so what is the advantage in creating an XML file.

    At a later stage I will create a windows form that will be able to edit, delete and add to the common file within Word.

    Sorry the question is so open ended however I have never had experience with databases.

    Thanks

    Tuesday, October 01, 2013 4:16 AM

Answers

  • <<So as you hinted before it sounds as if I have to go beyond a text file and start using SQL.>>

    It doesn't have to be SQL. It can be any kind of storage system that's convenient for you to use and supports the functionality required.

    I think you need to take some time and think through

    - exactly what you need to store (text only, formatting, meta-data, etc.)
    - how you want to organize the information (sorting, split into categories, etc.)
    - how much data might be accumulated (affects the type of storage)
    - whether people may need to edit what's being stored outside of your application
    - in what manner the data will be accessed (only by you, by a group of people, singly or simultaneously, etc.)

    After you know everything about the data, you then look at possibilities for storing it. You need to be sure the storage method you choose can accomodate all your needs. If there's more than one, then you look what's most "comfortable" for you to work with.

    Just FWIW I'm a member of the support team for a product called SmartDocs that, it sounds like, does basically what you describe and more. The product stores "snippets" (text to be re-used by many people and/or for more than one document) in SharePoint.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, October 02, 2013 2:12 PM
    Moderator
  • Mmmm... I'm not really a database person, although I've had experience with databases it's been more on the "consumer" end and less on the storage and configuration side.

    Besides SQL Server and Sharepoint, Access is also a possibility. It's part of Office (pro and higher editions) and is more a "desktop" application than for large-scale use. It's relational, so it's fairly easy to export/import to/from SQL server if you'd decide to go that way. More recent versions also interact with SharePoint. XML is also a possibility if you need to store information that doesn't fit into a "flat table" format. It doesn't sound like that's the case, though...

    Also, have you looked into using Word's built-in BuildingBlocks feature? This would let you store the text by categories and galleries, making filtering for presentation to the user simpler. There's also a content control that can display a filtered list of Building Block entries as a drop-down. Building Block entries are stored in templates that are loaded into memory (meaning they'd be outside any document the user is working with); they can be created via the Word API or using Open XML technology.

    << if I insert text into word does word automatically format it or will it insert it as a basic format. If it is a basic format then yes I will need it formatted to suit the documents formating>>

    That's going to depend on how it's been stored. If it's been stored as text-only (which will be the case with a classic database program), then the text will definitely adjust itself to the formatting of the range where it's being inserted.

    One thing that will be difficult - perhaps impossible - for you to achieve is "When the user types in text at specific locations I want a drop box to appear and provide possible solutions (the most probably at the top and the least probably at the bottom) which when the user clicks on the text it will insert the text." The reason being that Word has no event you can trap that occurs when the user types on the keyboard. Perhaps use content controls so that you can get "context-sensitive" content in a custom task pane. From there, maybe VBA macros linked to KeyBindings to "trap" what the user is typing and feed that back to the code that manages the custom task pane...


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, October 03, 2013 3:42 PM
    Moderator
  • You'd have to create a KeyBinding for each and every key on the keyboard that the user could use while typing. Usually, you'd do this in a template and provide the template with the keybindings and macros already in-place. The issue is, in order to create a keyboard shortcut to a macro for "normal" keys (instead of Ctrl+ or Alt+) you can't use the user interface, you have to code it.

    The link you've provided is for WINDOWS, you need to look at the information for WORD

    http://msdn.microsoft.com/en-us/library/office/ff838703.aspx

    This is a very complex undertaking and one I haven't done in, literally, years. Since this cannot be used with the VSTO technology and is only available for VBA, I suggest you pursue such a discussion in the Word for Developers forum.

    http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 04, 2013 3:06 PM
    Moderator

All replies

  • I think the question of where the information is best stored depends on organization/retrieval.

    Just writing it, line-by-line, into a text file doesn't give you any way to organize or retrieve the information, except reading line-by-line. Question is, does that do you any good? How do you eventually plan to use this text? Will you want to access it by categories, for example?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, October 01, 2013 4:10 PM
    Moderator
  • Cindy

    Thanks for your response.

    It will be used in a conditions report with generic sentences (as comments) that will be used in future reports. Most of the comments will be under 2 lines of text however do need flexibility to go to 3 lines.

    Eventually I will want to place it in categories.

    There will be specific areas were the text is inserted and I want to as the user types to display the possible comment options in say a drop down menu.

    So as you hinted before it sounds as if I have to go beyond a text file and start using SQL.

    Wednesday, October 02, 2013 2:21 AM
  • <<So as you hinted before it sounds as if I have to go beyond a text file and start using SQL.>>

    It doesn't have to be SQL. It can be any kind of storage system that's convenient for you to use and supports the functionality required.

    I think you need to take some time and think through

    - exactly what you need to store (text only, formatting, meta-data, etc.)
    - how you want to organize the information (sorting, split into categories, etc.)
    - how much data might be accumulated (affects the type of storage)
    - whether people may need to edit what's being stored outside of your application
    - in what manner the data will be accessed (only by you, by a group of people, singly or simultaneously, etc.)

    After you know everything about the data, you then look at possibilities for storing it. You need to be sure the storage method you choose can accomodate all your needs. If there's more than one, then you look what's most "comfortable" for you to work with.

    Just FWIW I'm a member of the support team for a product called SmartDocs that, it sounds like, does basically what you describe and more. The product stores "snippets" (text to be re-used by many people and/or for more than one document) in SharePoint.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, October 02, 2013 2:12 PM
    Moderator
  • Hi Cindy

    Thank you for that.

    SQL was the only database I know so if you could list or elaborate on the various useful databases that would be great.

    Could you outline the advantages and limitations (over other database technologies) in using SmartDocs.

    Not knowing alot about databases, I will try to answer your questions

    - if I insert text into word does word automatically format it or will it insert it as a basic format. If it is a basic format then yes I will need it formatted to suit the documents formating

    - I will want to sort the information. When the user types in text at specific locations I want a drop box to appear and provide possible solutions (the most probably at the top and the least probably at the bottom) which when the user clicks on the text it will insert the text. I realise this will be hard to program and this can be developed at a later stage. At the very minimum I will want to insert text that is categorised from a form.

    - If I work off that say 50,000 words is 1MB lets overestimate and say 10MB worth of MS Word text

    - for the time being I will only use the program only on my local machine and obviously will only be accessed by myself.

    Obviously it is at the early stages and I am currently just getting my head around all these questions you have raised.

    Thanks again your feedback.

    Thursday, October 03, 2013 1:38 AM
  • Mmmm... I'm not really a database person, although I've had experience with databases it's been more on the "consumer" end and less on the storage and configuration side.

    Besides SQL Server and Sharepoint, Access is also a possibility. It's part of Office (pro and higher editions) and is more a "desktop" application than for large-scale use. It's relational, so it's fairly easy to export/import to/from SQL server if you'd decide to go that way. More recent versions also interact with SharePoint. XML is also a possibility if you need to store information that doesn't fit into a "flat table" format. It doesn't sound like that's the case, though...

    Also, have you looked into using Word's built-in BuildingBlocks feature? This would let you store the text by categories and galleries, making filtering for presentation to the user simpler. There's also a content control that can display a filtered list of Building Block entries as a drop-down. Building Block entries are stored in templates that are loaded into memory (meaning they'd be outside any document the user is working with); they can be created via the Word API or using Open XML technology.

    << if I insert text into word does word automatically format it or will it insert it as a basic format. If it is a basic format then yes I will need it formatted to suit the documents formating>>

    That's going to depend on how it's been stored. If it's been stored as text-only (which will be the case with a classic database program), then the text will definitely adjust itself to the formatting of the range where it's being inserted.

    One thing that will be difficult - perhaps impossible - for you to achieve is "When the user types in text at specific locations I want a drop box to appear and provide possible solutions (the most probably at the top and the least probably at the bottom) which when the user clicks on the text it will insert the text." The reason being that Word has no event you can trap that occurs when the user types on the keyboard. Perhaps use content controls so that you can get "context-sensitive" content in a custom task pane. From there, maybe VBA macros linked to KeyBindings to "trap" what the user is typing and feed that back to the code that manages the custom task pane...


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, October 03, 2013 3:42 PM
    Moderator
  • Cindy

    Thank you so much for that feedback.

    I might start and divert my attention firstly to learning and using SQL but I have made notes to investigate the other types.

    I had a quick look at Keybindings at the following link:

    http://msdn.microsoft.com/en-us/library/system.windows.input.keybinding(v=vs.100).aspx

    however I am confused about what methods I should be looking at. If I were to compare the text entered with possible matches dynamically (ie if the next is modified then the possible matches change) what methods of the keybindings I should be looking at.

    Friday, October 04, 2013 6:22 AM
  • You'd have to create a KeyBinding for each and every key on the keyboard that the user could use while typing. Usually, you'd do this in a template and provide the template with the keybindings and macros already in-place. The issue is, in order to create a keyboard shortcut to a macro for "normal" keys (instead of Ctrl+ or Alt+) you can't use the user interface, you have to code it.

    The link you've provided is for WINDOWS, you need to look at the information for WORD

    http://msdn.microsoft.com/en-us/library/office/ff838703.aspx

    This is a very complex undertaking and one I haven't done in, literally, years. Since this cannot be used with the VSTO technology and is only available for VBA, I suggest you pursue such a discussion in the Word for Developers forum.

    http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 04, 2013 3:06 PM
    Moderator
  • Thanks Cindy. I will post in the Word for Developers forum

    Can you implement the VBA into the visual studio solution or is this done in the Visual Basic Editor in word.

    Monday, October 07, 2013 9:39 AM
  • VBA code must be managed in Word's VBA editor. Theoretically, you can write it in any text editor, then copy it in or import it. But then you wouldn't have the advantage of IntelliSense or in-place debugging.

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, October 08, 2013 4:02 PM
    Moderator
  • Thanks for that

    What is the best way to link the VBA with your VSTO COM Add-in. Do I have to create in VSTO a .docm file and insert the VBA into it (if that can be done).

    Tuesday, October 08, 2013 10:53 PM