Export Notes data to Excel - template location

Hi experts,
I'm using some script to export data to Excel that starts like this:
  ' Prepare MS Excel for work
      Set xlApp = CreateObject("Excel.Application")
      Set xlWB = xlApp.Workbooks.Add("C:\Program Files\Microsoft Office\Templates\template1.xlt")
Now that works fine providing the template is in the specified location, but I'm finding problems in that some people don't keep their templates in this directory and I'm thinking it might be better to put the template in the same directory as their Notes files. Normally this will be C:\Notes\Data\ probably, but again people can choose something else. So I'm wondering, if I place the template in whatever directory the user is using for storing his database, then can we alter the code above to look in the same directory as the database is located whatever it is, without actually specifying the path as done above?
Cheers,
Stuart
StuartOrdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
Why don't you store the company templates in a Notes-database, or in the same database? And then save it in a know directory. You can also ask Excel for the default template directory.
0
HemanthaKumarCommented:
Instead of distributing templates across local workstations, I would suggest you to keep it on a file server and access it from that share. In this way it is easy to distribute any changes to the template and maintain it centrally from one location.

eg:
     Set xlApp = CreateObject("Excel.Application")
     Set xlWB = xlApp.Workbooks.Add("\\Server\ShareName\Microsoft Office\Templates\template1.xlt")

PS: Create a read only share so that nobody writes info in this area.

~Hemanth
 
0
StuartOrdAuthor Commented:
Thanks for the comments.
sjef_bosman:How do I store the template "in the same database"? If it's linked to the database in some way, that would be fine. How do I then point the agent at this location?
Hemanth (hi again!): I'm working in a much smaller world than yours and the databases are usually running on a local PC with no Notes server. Few people use it as it's specialised. So I really need it on the local PC
Regards,
Stuart
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

HemanthaKumarCommented:
Well then I would go with sjef suggestion
0
qwaleteeCommented:
For sjef's suggestion, here are some details:

You could store teh template in a profile document.  Create a form, put a rich text field on it, name it something like EXCEL TEMPLATE and mark it to not be available for compose or search.

Create an action button or agent with the formula:

@Command([EditProfile]; "EXCEL TEMPLATE")

Run that code, the form pops up, attach the template file, save and close.

Now, the following code can access this file:

CONST FILE_NAME = "template1.xlt"
Dim s as new notesSession
Dim db as notesDatabase
Set db = s.currentDatabase
Dim profile as notesDocument
Set profile = db.getProfileDocument("EXCEL TEMPLATE")
Dim excelFile as notesEmbeddedObject
Set excelFile = doc.getAttachment(FILE_NAME)
excelFile.extractFile("C:\" & FILE_NAME)
0
Sjef BosmanGroupware ConsultantCommented:
If I understand you correctly that your users don't replicate with a server, you'd run in trouble refreshing your Excel-template if (when) that becomes necessary. I therefore assume that replication is done every now and then, but not too often. The most flexible idea is to put the template inside a document, but not necessarily in a Profile document. On a good day you need more templates for other purposes, so you add a template to your template database. It's probably best to create a new form in your database and a view to find documents created with that form. You could protect your templates from being modified with the usual Reader- and Author-fields.

You could also look into the Document Library template in standard Notes installations, and then use stuff you find in there.

How to find your excel-template:

Set db= s.CurrentDatabase
Set view= db.GetView("Templates")
Set doc= view.GetDocumentByKey("Excel-template", True)

followed by portions of qwaletee's code to extract the template.

Sjef
0
StuartOrdAuthor Commented:
OK, I'm trying this. Part of my code is now:

Dim excelFile As notesEmbeddedObject
      Set view=db.GetView("Excel template")
      Set doc=view.GetFirstDocument
      Set excelFile = doc.getAttachment("LEAC.xlt")
      Call doc.ExtractFile( "c:\" & "LEAC.xlt" )

I have a view called "Excel templates" as you can see, and it contains one document made with a form called "ExcelTemplateForm" that has a rich text field called "Exceltemplate1". Into this document I attached my template "LEAC.xlt".

When I run this agent, it fails at the last line shown, with the error "Illegal use of property". I copied the style of the line from Designer help - but that's not the first time I've done thta and it failed! Isn't the method ExtractFile embedded into Notes somehow?
Stuart
0
Sjef BosmanGroupware ConsultantCommented:
Extractfile should be called differently. Here part of some sourcecode for a Word-attachment:

            Set item= doc.getfirstitem(fname)
            Set eo= item.EmbeddedObjects(0)
            filepath= filepath + "\" + eo.source
            Call eo.extractfile(filepat)

It's probably not an Attachment, it's embedded into a rich-text field.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StuartOrdAuthor Commented:
Thanks sjef-bosman
The code I got to work is as follows:
                Dim xlApp As Variant
      Dim xlsheet As Variant
      Dim xlWB As Variant
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim count As Integer
      Dim session As New NotesSession
      Set db = session.CurrentDatabase
               
                'New bit for embedded template
      Dim excelFile As notesEmbeddedObject
      Set view=db.GetView("Excel template")
      Set doc=view.GetFirstDocument
      Set excelFile = doc.getAttachment("LEAC.xlt")      
                Call excelFile.ExtractFile( "c:\LEAC.xlt")

      ' Prepare MS Excel for work
      Set xlApp = CreateObject("Excel.Application")
      Set xlWB = xlApp.Workbooks.Add("C:\LEAC.xlt")
              etc

Now I need to alter it to hold several templates in the database.... but I'll let you know if I get stuck!

Regards,
Stuart
0
StuartOrdAuthor Commented:
Hey, it's a doddle, just several rich text fields in the same form into which I attached the other templates, and the other scripts are more or less the same with the new teplate name in the code. I wish it were all so easy.
0
qwaleteeCommented:
Doddle?
0
Sjef BosmanGroupware ConsultantCommented:
Some "free" advice (and thanks for the points!):

Maybe you'd better create a document per template, all with a template form:
- you won't be depending on the names of the fields
- you don't have to change the design if you have to add a template
- you can pick the template out of a view
- the code will be the same for all templates (same fieldname)
- it's a lot neater to do it this way
0
qwaleteeCommented:
Sjef,

He's probably OK this way.  He's grabbing it straight by filename, so he is not dependant on field name anyway.
0
StuartOrdAuthor Commented:
Doddle = slang for very easy.
I wondered about making several template forms, but I wasn't sure how to grab the second and third documents as appropriate for the template being sought by each agent, and since this way worked first time, I applied "if it ain't bust, don't fix it"  ;-)
Just in case - bust = broken ;-o


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.