Results 1 to 2 of 2
  1. #1

    Inter Process Communications

    Hi Everyone,

    I'm a little at a loss here.

    What is the best way of sending data to an out of process VB application? I'm considering either named pipes or windows sockets. Also, I was hoping to be able to "attach" to an existing Excel Spreadsheet and read/modify some values from a Visual Basic application. Does anyone know exactly how to read/write to a cell in a spreadsheet from an external (VB) application while Excel is running?

    Thanks in advance,


  2. #2

    Re: Inter Process Communications

    Ho Puppy,

    To read/write from/to a running Excel application:

    First of all, you have to add a reference to the 'Microsoft Excel 8.0 Object Library' (or 9.0 if running Excel 2000).

    Thne this code snappet shows how to do this :

    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Dim vTest1 As String, vTest2 As String

    On Error Resume Next
    Set xlApp = GetObject(,"Excel.application") 'This line will capture the running application
    If Err.Number <> 0 Then
    Set xlApp = CreateObject("Excel.Application") 'In case Excel is not running, it will be opened.
    End If
    On Error GoTo 0

    'Now assign trhe workbook MyFile.xls to the xlBook variable
    'If it's not open, open it
    On Error Resume Next
    Set xlBook = xlApp.Workbooks("MyFile.xls")
    If err.Number <> 0 Then
    Set xlBook = xlApp.Workbooks.Open("C:MyPathMyFile.xls")
    End If
    On Error GoTo 0

    'Now assign the wanted sheet (Sheet1 in example) to the xlSheet variable

    Set xlSheet = xlBook.Worksheets("Sheet1")

    'Now this shows how to read data from cell B5 (row 5, column 2) in two ways)
    vTest1 = xlSheet.Range("B5")
    vTest2 = xlSheet.Cells(5,2)

    'And now we will write these values back to cell C5 (row 5 ,column 3)
    xlSheet.Cells(5,3) = vTest2

    'Save the workbook

    'Close the workbook

    'Quit excel


    'Release object variables
    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing

    Have Fun

Posting Permissions

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