ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open CSV File (https://www.excelbanter.com/excel-programming/443426-open-csv-file.html)

Steve H[_2_]

Open CSV File
 
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!

Dave Peterson[_2_]

Open CSV File
 
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!



On 07/28/2010 07:29, Steve H wrote:
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!


--
Dave Peterson

Steve H[_2_]

Open CSV File
 
On Jul 28, 10:49*am, Dave Peterson wrote:
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!

On 07/28/2010 07:29, Steve H wrote:

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!


--
Dave Peterson


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

Dave Peterson[_2_]

Open CSV File
 
I'd still qualify the range.



On 07/28/2010 12:05, Steve H wrote:
On Jul 28, 10:49 am, Dave wrote:
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!

On 07/28/2010 07:29, Steve H wrote:

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!


--
Dave Peterson


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


--
Dave Peterson


All times are GMT +1. The time now is 12:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com