Open CSV File

  • Thread starter Thread starter Steve H
  • Start date Start date
S

Steve H

I am using Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum)) to open
a csv file. After the file is opened I would like to make changes to
the file. The code is stored in another file Basebook. The code
works fine for opening the file and it appears that mybook is the
active book. However the changes that I make are being made to
Basebook and not mybook. The code works flawlessly in another
instance opening a different file, so it appears as though there may
be some problem with the file.

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
Range("F2").Formula = "=SUMPRODUCT(--($e$3:$e
$500=""Dog""),roundup(1.02*(f$3:f$500),0))"

Any ideas?
Thanks!
 
My first guess would be that the code is in a worksheet module.

If that's true, then the unqualified range (Range("F2")) refers to the sheet
that owns the code -- not the activesheet.

If the code is in a General module, then this isn't a good guess. The
unqualified range should refer to the activesheet.

In either case, I'd qualify that range.

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.worksheets(1).Range("F2").Formula _
= "=SUMPRODUCT(--($e$3:$e$500=""Dog""),roundup(1.02*(f$3:f$500),0))"

I've never seen a situation where qualifying the range is a bad idea!
 
My first guess would be that the code is in a worksheet module.

If that's true, then the unqualified range (Range("F2")) refers to the sheet
that owns the code -- not the activesheet.

If the code is in a General module, then this isn't a good guess.  The
unqualified range should refer to the activesheet.

In either case, I'd qualify that range.

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.worksheets(1).Range("F2").Formula _
  = "=SUMPRODUCT(--($e$3:$e$500=""Dog""),roundup(1.02*(f$3:f$500),0))"

I've never seen a situation where qualifying the range is a bad idea!

Yes that was it. I changed it to a General Module and it is working
now.
Thanks!!!
 
Back
Top