Advertisement
Guest User

Untitled

a guest
Apr 14th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '#Reference {F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0#C:\WINDOWS\System32\COMDLG32.OCX#Microsoft Common Dialog Control 6.0
  2. '#Reference {00020813-0000-0000-C000-000000000046}#1.4#0#C:\Program Files\Microsoft Office\Office10\EXCEL.EXE#Microsoft Excel 10.0 Object Library
  3. '#Reference {420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#C:\WINDOWS\System32\scrrun.dll#Microsoft Scripting Runtime
  4. Sub Main
  5. Dim xlsFile As Variant
  6. Dim i As Long
  7. Dim img As Image
  8. Dim imgs As Images
  9. Dim r As PropertyRecord
  10. Dim k As Integer
  11.  
  12.     On Error GoTo catch
  13.  
  14.     Dim db As Database
  15.     Set db = IMatch.ActiveDatabase
  16.     If db Is Nothing Then
  17.         MsgBox "Please open a database first!"
  18.         Exit Sub
  19.     End If
  20.  
  21.     Dim iset As Images
  22.     Set iset = db.ActiveSelection
  23.     If iset Is Nothing Then
  24.         MsgBox "Please open a database first!"
  25.         Exit Sub
  26.     End If
  27.  
  28.  
  29.     If iset.Count = 0 Then
  30.         MsgBox "Please open a database first!"
  31.         Exit Sub
  32.     End If
  33.  
  34.     xlsFile = GetFilePath (,"Excel Files|*.xls*", "Choose file", 0)
  35.     If xlsFile = "" Then
  36.         Exit Sub
  37.     End If
  38.  
  39.     Dim oExcelApp   As Excel.Application
  40.     Dim oWs         As Excel.Worksheet
  41.  
  42.     Set oExcelApp = CreateObject("EXCEL.APPLICATION")
  43.     oExcelApp.Visible = False
  44.     oExcelApp.Workbooks.Open FileName:=xlsFile, ReadOnly:=True, ignoreReadOnlyRecommended:=True
  45.     Set oWs = oExcelApp.ActiveSheet
  46.  
  47.  
  48.  
  49.     IMatch.WaitDialogOpen "Importing...",0,oWs.Cells.SpecialCells(xlCellTypeLastCell).Row - 1,True
  50.  
  51.     db.BeginTransaction False
  52.  
  53.     For i = 2 To oWs.Cells.SpecialCells(xlCellTypeLastCell).Row
  54.         IMatch.WaitDialogSetText "Processing " & oWs.Cells(i, 1).Text
  55.         If oWs.Cells(i, 1).Text <> "" Then
  56.             Set img = iset(oWs.Cells(i, 1).Text)
  57.             If sresult <> "" Then
  58.                 sresult = sresult & vbCrLf
  59.             End If
  60.             If Not img Is Nothing Then
  61.                     sResult = sResult & vbCrLf & "** " & oWs.Cells(i, 1).Text & " found in image selection!"
  62.                     Set r = img.Properties
  63.                     k = 2
  64.                     Dim s As String, s2 As String
  65.                     Do Until oWs.Cells(1, k) = ""
  66.                         s = oWs.Cells(1, k)
  67.                         r.Property(s) = oWs.Cells(i, k)
  68.                         k = k + 1
  69.                     Loop
  70.                     r.Update
  71.             Else
  72.                 sResult = sResult & vbCrLf & oWs.Cells(i, 1).Text & " not found in image selecion"
  73.             End If
  74.         End If
  75.         If IMatch.WaitDialogIsCanceled Then
  76.             Exit For
  77.         End If
  78.         IMatch.WaitDialogSetPercentage i
  79.     Next i
  80.  
  81.     db.EndTransaction Not Application.WaitDialogIsCanceled
  82.  
  83.  
  84.     Begin Dialog UserDialog 400,203,"Process Results" ' %GRID:10,7,1,1
  85.         Text 20,7,200,14,"Results:",.Text1
  86.         TextBox 30,28,320,126,.txtResult,1
  87.         OKButton 140,168,120,21
  88.     End Dialog
  89.  
  90.     Dim dlg1 As UserDialog
  91.     If sResult = "" Then
  92.         dlg1.txtResult = "No files."
  93.     Else
  94.         dlg1.txtResult = sResult
  95.     End If
  96.     Dialog dlg1
  97.  
  98.  
  99.     GoTo finally
  100.  
  101. catch:
  102.     MsgBox (Err.Description)
  103.  
  104. finally:
  105.  
  106.     oExcelApp.Quit
  107.     Set oExcelApp = Nothing
  108.  
  109. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement