Consulting

Results 1 to 3 of 3

Thread: Solved: Get Excel data for Outlook UserForm

  1. #1

    Solved: Get Excel data for Outlook UserForm

    I have an Outlook UserForm that needs to populate a ComboBox from an Excel spreadsheet.

    However, i am new at all this and cannot work out how to open a specified workbook / spreadsheet / cell and obtain the values to populate the Combobox.

    Thanks all

    (Windows XP / Office 2003)

  2. #2
    It's actually not to hard. You will want to go to the tools menu of the VBE and set a reference to Microsoft Excel then you can pull that data as needed using the 4 basic excel objects (Application, Workbook, Worksheet, Range).

    Here is some example syntax that should get you started. Make sure you set the reference before you try to use the code.

    [VBA]Sub Example()
    Dim xlApp As Excel.Application
    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet
    Dim rng As Excel.Range
    Set xlApp = New Excel.apl
    Set wb = xlApp.Workbooks.Open("C:\Test.xls", Radonly:=True)
    Set ws = wb.Worksheets("Sheet1")
    Set rng = ws.Cells(1, 1)
    MsgBox rng.Value
    wb.Close SaveChanges:=False
    xlApp.Quit
    End Sub[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    Thank you very much
    That has worked well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •