Accessing workbook after .OpenText

  • Thread starter Thread starter Phil_V
  • Start date Start date
P

Phil_V

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
Wen
-------------------


Ok, the problem I have at the moment is that I need to open this cs
file, which is performed fine above into a new workbook. However how d
I then get a 'pointer' to that workbook. I need to be able to perfor
operations on the opened .csv file, and my original workbook, (the on
with the macro in it), and then copy data out of the .csv file into th
original workbook.

I'm guessing it would be something like:

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

Any ideas?

Thanks,

Phi
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top