Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

import document

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
phuongnguyen
Asked:
phuongnguyen
  • 2
  • 2
1 Solution
 
madheeswarCommented:
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
 
Sjef BosmanGroupware ConsultantCommented:
So EE indeed IS a rent-a-coder site! You already solved the problems the questioner was still unaware of.

Sjef ;)
0
 
CRAKCommented:
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
 
madheeswarCommented:
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
 
CRAKCommented:
All well here, thanks.
Don't worry about the code.... I think any other expert would have done the same thing!
;-))
0
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now