2

Okay SO. I need some guidance. I apologize for the length of this post, but I need to provide some details:

I've got someone who is interested in me to do a small project for them. The application in general is a fairly straightforward employee record keeping / documentation app, but it makes pretty heavy use templated Word and Lotus documents. The idea is you select the employee “event” such as commendation, promotion, discipline, etc., and it loads the appropriate template doc and you fill it in from there, and later you can select an employee, view all the “events,” and view the individual documents associated with each one.

Thus, the app must know where the .docs are saved when the user is done.

The client actually has a v1 of this app (it doesn’t do any management of the files or anything, just launches Word/Lotus with the document you wanted to view in a new instance, presumably via a system() call.) We’ve not gotten into a detailed requirements phase, but the client and I agree that for this to really work, some kind of control over where the user saves the .doc’s to is going to be critical , because otherwise the app provides them with the new copy of the template doc, they "Save as" somewhere else, and the app is pointing to the blank copy it provided them with.

Obviously, I can’t think of a way to achieve “Save as” restriction/control in any way via just launching a new instance of Word. The client has the idea of an embedded Word/Lotus instance in the app with the template doc when you choose one, but I’ve few reservations with that:

  • I’ve dug around online and I’ve read that whichever version of Word I borrow MSWORD.OLB from will be the one the end user would require?
  • I’ve tried to do the MSDN example of embedding a Word doc from here, but as I’ve come to get used to, the MSDN example doesn’t even compile.
  • Even if I CAN figure out how to embed a .doc file into their application, I don’t know that I could control the use of “Save as…”
  • All of this STILL hasn’t touched on Lotus (!)

So… instinctively, I feel the embedded Word/Lotus thing has to be more work than it’s worth in the end.

So I’ve had a few other ideas brewing around.

  1. One is looking into using Office XML (and if there’s a lotus equivalent), and get the user’s “inputs” separately and generate the document on the fly each time. I’m not particularly thrilled with that idea, but I think it COULD work, provided I just use old features to try and stay far backwards compatible.
  2. Get user’s “inputs” separately and generate a document in HTML. Meh. Works, very cross platform and easily parsed and understood, but not good if you want to be able to email it to someone (who emails a .html? Works, yes, very unconventional which to the average user will throw them off) and even worse if you need to email it to someone for revisions…
  3. Perhaps some kind of editable PDF? I know there are PDF libraries out there, and the more I stew on it, the more this sounds like the best option, though I’ve not done much work with PDFs and I don’t know how easily embeddable they are / what options one has when creating them. I know they can be save-disabled, I’ve had that with my bloody state taxes before.

I need some input here. Here’s the TLDR questions:

  1. Is launching a new instance of Word for each .doc as bad as I feel, given user can “Save as” document wherever and then application is left pointing to a blank document?
  2. Is trying to support embedded Word as big of a trouble as I feel like it is / more work than it’s worth / likely to cause problems with supporting multiple versions of Word? (Forward compatibility as well as currently released versions?)
  3. What are thoughts on the PDF plan?
  4. Any other good ideas?
trycatch
  • 568
  • 1
  • 8
  • 17
  • +1 good question with lots of detail, thank you! My gut reaction is that I agree that embedding is a bad idea. As you've intuited, embedding it will not give you control over its implementation. Similarly, you will have a problem in that you might find a registry path that shows where word saves to by default but I can bet that Lotus won't use that. – Russ Clarke Aug 12 '11 at 01:18
  • Well, even if I can find where it saves to by *default*, I can't keep the user from saving to another location. If I can't do that, then my app has no idea where the user might have actually saved the file. The best I could do is copy the template to something like /doc/LastNameFirstNameTemplateName.doc and HOPE they just use Save instead of Save As... Maybe if I could DIRECTLY embed the doc in the GUI and remove the menu bar (ribbon? another reason embedding makes me nervous, major version differences..), then I could MAYBE make it work.. but.. that's lots of maybe.. – trycatch Aug 12 '11 at 01:23
  • 1
    Indeed. One thing; How many people will use this app, Are you going to do a lot of coding where instead user education would suffice ? This is almost starting to sound like a project where Microsoft Sharepoint might be a solution. – Russ Clarke Aug 12 '11 at 01:27
  • 2
    Your best bet is probably finding a PDF library, though I don't know what's available there. Do not attempt to embed Word into your application with C++, you're better off bashing your head against a wall. It is more do-able if you switch to C#, however; you can also 'intercept' the save functionality to enforce restrictions on save location. Overall, I would consider a system like this lazy/a hack, so don't expect a good solution. It's most likely going to be dirty no matter what you do. – Collin Dauphinee Aug 12 '11 at 01:27
  • @Russ C: Well, the idea is one user per install. Each user uses it to maintain their group of people and whatnot. I hadn't considered SharePoint, I don't really know much about it. +1 for something to look into! – trycatch Aug 12 '11 at 03:43
  • @dauphic: I'd considered C# but I'd read somewhere that .NET didn't support OLE or something to that effect. I don't recall specifically. I hadn't considered a PDF library though. I need to look into that. +1 for the suggestion. – trycatch Aug 12 '11 at 03:45
  • By Lotus Documents, do you mean a Lotus Notes Database? From what you've written, you really can do the whole thing from within Lotus Notes storing both the templates and the completed word documents in the database. I've worked on many systems that worked this way. – Jon McAuliffe Aug 12 '11 at 04:52
  • @Jon McAuliffe well.. I haven't actually dived into the Lotus side too deeply, but it's largely the same as with Word.. a set of template docs and you get a newly generated blank one and fill it in.. I need to read up more on Lotus. – trycatch Aug 12 '11 at 05:56

1 Answers1

2

Word does allow for programming some "Save" and "Save As" control via its object model. Any subroutines coded in VBA and placed into your Word template will be copied into all documents generated from that template. Additionally, most menu and Ribbon commands can be intercepted by creating a module containing subroutines named for the intercepted commands. So, for example, if a module contains a sub named FileSaveAs(), any code in that sub will be executed instead of the standard File|Save As command. Lastly, this code will replace Save As commands executed via keystroke, toolbar, menu, or Ribbon.

The code below will launch a dialog box to a predetermined path whenever a "Save" or "Save As" command is executed:

Sub FileSave()
ControlSaveLocation
End Sub

Sub FileSaveAs()
ControlSaveLocation
End Sub

Sub ControlSaveLocation()
Dim Directory As String
Directory = "C:\Documents\"
With Application.Dialogs(wdDialogFileSaveAs)
    .Name = Directory
    .Show
End With
End Sub

Hope this helps.

joeschwa
  • 3,083
  • 1
  • 21
  • 41
  • Oh wow. I had no idea one could do that... the only issue then would be being able to export a copy without that restriction if you needed to email someone a copy (obviously the recepient would need to be able to save it to a different location.) – trycatch Aug 12 '11 at 06:01
  • There are probably better ways to remove the restriction for external computers, but off the top of my head one could create a very uniquely named Word document -- for example "Do_Not_Remove_This_Document_It_Is_Needed_For_App_To_Run" -- and place it in the folder that the documents created by the app reside in. Then test for it's existence in VBA so that if it's there the restriction is in place and if not it's ignored. – joeschwa Aug 12 '11 at 14:30
  • Hrm. That's a possibility. I'll look into it. I need it to control precisely where you're able to save, so I'll need to verify one can do that. – trycatch Aug 12 '11 at 17:30