+ Reply to Thread
Results 1 to 5 of 5

Inserting data into a seperate Excel workbook

  1. #1
    Jon
    Guest

    Inserting data into a seperate Excel workbook

    All,
    I am interested in having a macro from Excel Workbook A insert data into
    seperate and unopened Workbook B. Workbook B's name will vary. Is this
    possible and if so how should I go about it? Thanks in advance.
    --
    J

  2. #2
    anonymousA
    Guest

    Re: Inserting data into a seperate Excel workbook

    Hi,

    to work on a close file, you must use the ADO technique.
    Have a look in Excel VBA Help on ADO. By this way, you can extract datas or
    update them.There are some examples.

    So long

    "Jon" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > All,
    > I am interested in having a macro from Excel Workbook A insert data

    into
    > seperate and unopened Workbook B. Workbook B's name will vary. Is this
    > possible and if so how should I go about it? Thanks in advance.
    > --
    > J




  3. #3
    gocush
    Guest

    RE: Inserting data into a seperate Excel workbook

    If it is acceptable to open Workbook B, insert the data and close it at the
    speed of light, without the user seeing any change then you can use something
    like:

    Sub InsertData()
    Dim strFile as String
    strFile = "xxx"
    Application.ScreenUpdating=False
    With Workbooks
    .Open(strFile)
    'your code to insert data
    .Range("MyDestinationRange")="Hello"
    .Close True
    End with
    End Sub

    "Jon" wrote:

    > All,
    > I am interested in having a macro from Excel Workbook A insert data into
    > seperate and unopened Workbook B. Workbook B's name will vary. Is this
    > possible and if so how should I go about it? Thanks in advance.
    > --
    > J


  4. #4
    onedaywhen
    Guest

    Re: Inserting data into a seperate Excel workbook


    gocush wrote:
    > If it is acceptable to open Workbook B, insert the data and close it

    at the
    > speed of light, without the user seeing any change then you can use

    something
    > like <snip>


    Often it takes a little longer to open a workbook <g>. Here is the ADO
    equivalent for a *closed* workbook:

    Sub jtest()
    Dim strFile As String
    strFile = "xxx"
    Dim con As Object
    Set con = CreateObject("ADODB.Connection")
    With con
    ..Open _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Extended Properties='Excel 8.0;HDR=NO';" & _
    "Data Source=" & strFile
    ..Execute "UPDATE MyDestinationRange SET F1 = 'Hello';"
    ..Close
    End With
    End Sub

    Jamie.

    --


  5. #5
    Jon
    Guest

    Re: Inserting data into a seperate Excel workbook

    Hmmm, just copied/pasted the code into the editor and got an error stating
    "Compile Error: Expected: Identifier or bracketed expression"

    Any ideas on what this is from? Thanks in advance.

    "onedaywhen" wrote:

    >
    > gocush wrote:
    > > If it is acceptable to open Workbook B, insert the data and close it

    > at the
    > > speed of light, without the user seeing any change then you can use

    > something
    > > like <snip>

    >
    > Often it takes a little longer to open a workbook <g>. Here is the ADO
    > equivalent for a *closed* workbook:
    >
    > Sub jtest()
    > Dim strFile As String
    > strFile = "xxx"
    > Dim con As Object
    > Set con = CreateObject("ADODB.Connection")
    > With con
    > ..Open _
    > "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > "Extended Properties='Excel 8.0;HDR=NO';" & _
    > "Data Source=" & strFile
    > ..Execute "UPDATE MyDestinationRange SET F1 = 'Hello';"
    > ..Close
    > End With
    > End Sub
    >
    > Jamie.
    >
    > --
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1