Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. Sub userFormTest()
  2.  
  3. Dim objExcel As Object
  4. Dim objWbk As Object
  5. Dim rngSearch As Object
  6. Dim rngFound As Object
  7. Dim targetCellValue As String
  8. Dim userChoice As Integer
  9.  
  10. Set objDoc = ActiveDocument
  11. Set objExcel = CreateObject("Excel.Application")
  12. Set objWbk = objExcel.Workbooks.Open("C:UsersDaveDocumentsTest_Definitions.xlsx")
  13. objExcel.Visible = True
  14. objWbk.Activate
  15.  
  16. With objWbk.Sheets("Sheet1")
  17.  
  18. Set rngSearch = .Range(.Range("A1"), .Range("A" & .Rows.Count).End(-4162))
  19.  
  20. Set rngFound = rngSearch.Find(What:="AA", After:=.Range("A1"), LookAt:=1)
  21.  
  22.  
  23.  
  24. If rngFound Is Nothing Then
  25.  
  26. UserForm1.Label1.Caption = "Acronym: AA" & vbCr & _
  27. "Definition: Not found, please enter a definition below" & vbCr & _
  28. " or choose to ignore this acronym"
  29. UserForm1.Show
  30.  
  31. 'an if statement here so that if the add button was pressed it adds to doc etc
  32.  
  33. Else
  34.  
  35. targetCellValue = .Cells(rngFound.Row, 2).Value
  36.  
  37. UserForm2.Label1.Caption = "Acronym: AA" & vbCr & _
  38. "Definition: " & targetCellValue
  39. UserForm2.Show
  40.  
  41. 'an if statement here so that if the add button was pressed it adds to doc etc
  42.  
  43. End If
  44.  
  45. End With
  46.  
  47. objWbk.Close Saved = True
  48.  
  49. Set rngFound = Nothing
  50. Set rngSearch = Nothing
  51. Set objWbk = Nothing
  52. objExcel.Visible = True
  53. Set objExcel = Nothing
  54. Set objDoc = Nothing
  55.  
  56. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement