Controling Excel using Word VBA
Z,
Set a reference to Excel from within your Word project (in the VBE) and use code like this, below.
You really didn't explain a lot of the particulars, but this should get you going.
HTH,
Bernie
MS Excel MVP
Sub Macro1()
Dim xlApp As Object
Dim xlBook As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim xlCell As Excel.Range
Dim myValue As String 'Redim to match your user-entered data type
myValue = "Find me" 'Get this from your user's entered value in the combobox
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True ' optional
Set xlBook = xlApp.Workbooks.Open("C:\DeleteMe.xls") ' change to actual file name
Set xlSht = xlBook.ActiveSheet
Set xlCell = xlSht.Range("A:A").Find(myValue) ' set search range
If xlCell Is Nothing Then ' add the value to the set at the bottom
xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp)(2).Value = myValue
MsgBox "Added " & myValue & " to cell " & _
xlSht.Cells(xlSht.Rows.Count, 1).End(xlUp).Address(False, False, xlA1, True)
xlBook.Save
xlBook.Close
Else
MsgBox "Found " & myValue & " in cell " & xlCell.Address(False, False, xlA1, True)
End If
xlApp.Quit
Set xlApp = Nothing
End Sub
"Zoltar54" wrote in message
...
Hello,
I am currently working on a project in Word VBA. The userform that I have
developed has a number of combo boxes which are populated from an Existing
Excel Workbook. What I would like to have happen is when a user enters
information into the combo box, the program searches the recordset and if the
entry does not exist to add it automatically.
I have asked this question in a few Word NG and have been subsequently
directed to an Excel NG. Any assistance that could be provided would be
greatly appreictaed.
Z
|