+ Reply to Thread
Results 1 to 2 of 2

Accessing workbook after .OpenText

  1. #1
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Post Accessing workbook after .OpenText

    Hi all,

    I have the following code in an Excel document:

    Please Login or Register  to view this content.
    Ok, the problem I have at the moment is that I need to open this csv file, which is performed fine above into a new workbook. However how do I then get a 'pointer' to that workbook. I need to be able to perform operations on the opened .csv file, and my original workbook, (the one with the macro in it), and then copy data out of the .csv file into the original workbook.

    I'm guessing it would be something like:

    with Workbooks(2).Worksheets(1).... etc, but I don't know how to make sure I am talking about the right workbook.

    Any ideas?

    Thanks,

    Phil

  2. #2
    Tom Ogilvy
    Guest

    RE: Accessing workbook after .OpenText

    You have the name of the workbook in Name

    Dim name
    Dim fullname
    Dim bk as Workbook
    name = Dir(ActiveWorkbook.Path & "\*.csv")
    While name <> ""
    fullname = ActiveWorkbook.Path & "\" & name
    MsgBox fullname
    Workbooks.OpenText _
    Filename:=fullname, _
    DataType:=xlDelimited, _
    comma:=True
    set bk = workbooks(name)
    ' now use bk to refer to the workbook

    ' Some code to go here....
    name = Dir
    Wend

    --
    Regards,
    Tom Ogilvy


    "Phil_V" wrote:

    >
    > Hi all,
    >
    > I have the following code in an Excel document:
    >
    >
    > Code:
    > --------------------
    > Dim name
    > Dim fullname
    > name = Dir(ActiveWorkbook.Path & "\*.csv")
    > While name <> ""
    > fullname = ActiveWorkbook.Path & "\" & name
    > MsgBox fullname
    > Workbooks.OpenText _
    > Filename:=fullname, _
    > DataType:=xlDelimited, _
    > comma:=True
    >
    > ' Some code to go here....
    > name = Dir
    > Wend
    > --------------------
    >
    >
    > Ok, the problem I have at the moment is that I need to open this csv
    > file, which is performed fine above into a new workbook. However how do
    > I then get a 'pointer' to that workbook. I need to be able to perform
    > operations on the opened .csv file, and my original workbook, (the one
    > with the macro in it), and then copy data out of the .csv file into the
    > original workbook.
    >
    > I'm guessing it would be something like:
    >
    > with Workbooks(2).Worksheets(1).... etc, but I don't know how to make
    > sure I am talking about the right workbook.
    >
    > Any ideas?
    >
    > Thanks,
    >
    > Phil
    >
    >
    > --
    > Phil_V
    > ------------------------------------------------------------------------
    > Phil_V's Profile: http://www.excelforum.com/member.php...o&userid=31857
    > View this thread: http://www.excelforum.com/showthread...hreadid=523144
    >
    >


+ 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