LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
controling a .xls from another .xls on-a-mission New Users to Excel 2 February 17th 06 06:28 AM
Excel User Form using 2 Combo Box with 1st Combon controling the 2 ca1358 Excel Programming 1 January 6th 06 12:27 AM
Controling Acrobat PDFs No Name Excel Programming 0 December 17th 04 04:41 PM
CheckBox controling a ComboBox Dillonstar Excel Programming 3 October 23rd 03 05:56 PM


All times are GMT +1. The time now is 01:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"