Solved

import document

Posted on 2004-08-30
5
370 Views
Last Modified: 2013-12-18
Hi,
I have an Excel file with 3 columns: Code, Name, Age. I want to import the data in this file to Notes by Notes script ('cause I want to check something before import). Please help. Is there any other way?
PN.
0
Comment
Question by:phuongnguyen
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
madheeswar earned 70 total points
ID: 11938812
Sub Initialize
'========================================================
      
      'Main Functionality: Import rows from Excel sheet and store in Notes documents, while user input file path.
      'Limitation: If there are consecutive 2 empty rows, then end the code
'========================================================
      Dim FileNum As Integer
      Dim xlFilename As String
      On Error Goto Errorhandler
      Filenum% = Freefile()
      xlFileName$ = Inputbox("What file name and path? example:C:\June282001.xls")
      
      If xlFileName$="" Then
            Exit Sub
      End If
      
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set doc = New NotesDocument(db)
      Dim One As String
      
      Dim row As Integer
      Dim written As Integer
      
 '// Next we connect to Excel and open the file. Then start pulling over the records.
      Dim Excel As Variant
      Dim xlWorkbook As Variant
      Dim xlSheet As Variant
      Print "Connecting to Excel..."
'      Set Excel = CreateObject( "Excel.Application.8" )
      Set Excel = CreateObject( "Excel.Application" )
      Excel.Visible = False '// Don't display the Excel window
      Print "Opening " & xlFilename & "..."
      Excel.Workbooks.Open xlFilename '// Open the Excel file
      Set xlWorkbook = Excel.ActiveWorkbook
      Set xlSheet = xlWorkbook.ActiveSheet
      
 '// Cycle through the rows of the Excel file, pulling the data over to Notes
      Goto Records
      Print "Disconnecting from Excel..."
      xlWorkbook.Close False '// Close the Excel file without saving (we made no changes)
      Excel.Quit '// Close Excel
      Set Excel = Nothing '// Free the memory that we'd used
      Print " " '// Clear the status line
      
      
Records:
      row = 0 '// These integers intialize to zero anyway
      written = 0
      tmpnullrows=0
      
      Print "Starting import from Excel file..."
      
      Do While True
Finish:
            With xlSheet
                  row = row + 1
                  
                  If .Cells (row, 1).Value = "" And .Cells(row,2).Value = "" _
                  And .Cells (row, 3).Value = "" And .Cells(row,4).Value = "" And .Cells (row, 5).Value = "" _
                  And .Cells(row,6).Value = "" And .Cells (row, 7).Value= "" _
                  And .Cells(row,8).Value = "" And .Cells (row, 9).Value = "" And .Cells (row, 10).Value = "" And .Cells (row, 11).Value = "" And .Cells (row, 12).Value = "" _
                  And .Cells (row, 13).Value = "" And .Cells (row, 14).Value = "" And .Cells (row, 15).Value = "" And .Cells(row,16).Value = "" Then
                        tmpnullrows=      tmpnullrows+1
                        If tmpnullrows=2 Then
                              Goto Done
                        End If
                        Goto Finish
                        
                  End If
                  
                  If .Cells (row, 1).Value = "Planning Year" And .Cells(row,2).Value= "ID" _
                  And .Cells (row, 3).Value = "Entered By" And .Cells(row,4).Value= "CRB Category" _
                  And .Cells (row, 5).Value = "FinSys Group" And .Cells(row,6).Value= "Finsys Owner" _
                  And .Cells (row, 7).Value = "Office Requested" And .Cells(row,8).Value= "Requestor Name" _
                  And .Cells (row, 9).Value = "Office Priority" And .Cells(row,10).Value = "Product" And .Cells(row,11).Value = "Prospective Project Name" _
                  And .Cells(row,12).Value = "Prospective Project Description" And .Cells(row,13).Value = "Application(s) Impacted" _
                  And .Cells(row,14).Value = "Requested Implementation Date" And .Cells(row,15).Value = "Funding Available from Office" _
                  And .Cells(row,16).Value = "Comments" Then
                        Goto Finish
                  End If
                  
                  'Set view = db.GetView("Main View")
                  Set doc = db.CreateDocument '// Create a new doc
                  doc.Form = "FinSysWP" '//FormName
                  doc.PlanYear = .Cells( row, 1 ).Value
                  doc.ID= .Cells(row, 2 ).Value 'Should be numeric
                  doc.EnteredBy = .Cells(row, 3).Value 'Should be Common user Name
                  doc.CRBCategory = .Cells( row, 4 ).Value
                  doc.FinSysGroup = .Cells(row, 5).Value
                  doc.FinSysOwner = .Cells( row, 6).Value
                  doc.OfficeRequested= .Cells(row, 7).Value
                  doc.Requestor = .Cells( row, 8).Value
                  doc.OfficePriority= .Cells(row, 9).Value
                  doc.Product = .Cells(row, 10).Value
                  doc.ProjectName = .Cells(row, 11).Value
                  doc.ProjDescription = .Cells(row, 12).Value
                  doc.ApplcnImpact = .Cells(row, 13).Value
                  doc.ImplDate = .Cells(row, 14).Value
                  doc.Funding = .Cells(row, 15).Value
                  doc.Comments = .Cells(row, 16).Value
                  tmpnullrows=0
                  Call doc.Save( True, True ) '// Save the new doc
                  written = written + 1
                  Print written
                  
                  Goto Finish
                  
            End With
      Loop
      Return
Errorhandler:
      Print "Error" & Str(Err) & ": " & Error$
      Resume Next
Done:
      Print "Finished importing"
End Sub
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11939362
So EE indeed IS a rent-a-coder site! You already solved the problems the questioner was still unaware of.

Sjef ;)
0
 
LVL 13

Expert Comment

by:CRAK
ID: 11939701
I bet madheeswar had hat code ready in a personal library somewhere!
Or he's got nothing better to do and desterate for points......
;-))
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 11940372
CRAK/SJEF,
Last week I wrote the above code for one application. So, placed it.

ofcourse I am desparate for points.

Hope you guys are doing well.

-Thanks
madheeswar
0
 
LVL 13

Expert Comment

by:CRAK
ID: 11940457
All well here, thanks.
Don't worry about the code.... I think any other expert would have done the same thing!
;-))
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

12 Experts available now in Live!

Get 1:1 Help Now