Solved

Export Notes data to Excel - template location

Posted on 2003-11-03
14
899 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:StuartOrd
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
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
 

Author Comment

by:StuartOrd
Comment Utility
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
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
Well then I would go with sjef suggestion
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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
 

Author Comment

by:StuartOrd
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 100 total points
Comment Utility
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
 

Author Comment

by:StuartOrd
Comment Utility
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
 

Author Comment

by:StuartOrd
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
Doddle?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
Sjef,

He's probably OK this way.  He's grabbing it straight by filename, so he is not dependant on field name anyway.
0
 

Author Comment

by:StuartOrd
Comment Utility
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now