Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub userFormTest()
- Dim objExcel As Object
- Dim objWbk As Object
- Dim rngSearch As Object
- Dim rngFound As Object
- Dim targetCellValue As String
- Dim userChoice As Integer
- Set objDoc = ActiveDocument
- Set objExcel = CreateObject("Excel.Application")
- Set objWbk = objExcel.Workbooks.Open("C:UsersDaveDocumentsTest_Definitions.xlsx")
- objExcel.Visible = True
- objWbk.Activate
- With objWbk.Sheets("Sheet1")
- Set rngSearch = .Range(.Range("A1"), .Range("A" & .Rows.Count).End(-4162))
- Set rngFound = rngSearch.Find(What:="AA", After:=.Range("A1"), LookAt:=1)
- If rngFound Is Nothing Then
- UserForm1.Label1.Caption = "Acronym: AA" & vbCr & _
- "Definition: Not found, please enter a definition below" & vbCr & _
- " or choose to ignore this acronym"
- UserForm1.Show
- 'an if statement here so that if the add button was pressed it adds to doc etc
- Else
- targetCellValue = .Cells(rngFound.Row, 2).Value
- UserForm2.Label1.Caption = "Acronym: AA" & vbCr & _
- "Definition: " & targetCellValue
- UserForm2.Show
- 'an if statement here so that if the add button was pressed it adds to doc etc
- End If
- End With
- objWbk.Close Saved = True
- Set rngFound = Nothing
- Set rngSearch = Nothing
- Set objWbk = Nothing
- objExcel.Visible = True
- Set objExcel = Nothing
- Set objDoc = Nothing
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement