Minggu, 10 Juni 2012

[ExcelVBA] Re: ReSOLVED: Opening a CSV file and populating cells just like Excel does

 



OOPS.

Well, it works as I pasted it here; in Excel 2007. I forgot/didn't know that Split creates an array, but it makes sense:

This works - no "0":
Dim FileNameOnly as String
...
FileNameOnly = StrReverse(Split(StrReverse(sFullFileName), "\")
...
Windows(FileNameOnly).Close

looks like 1 is the default and (Poking at the Object Browser I see) it is also using the defaults for the 'Limit' (whatever that is)and 'compare method'?

So, aparently VBA does something nice for you (behind your back) and puts the first part of the split onto a non-array variable. Thanks VBA

I sorta' hate it when VBA does something for you even if it is what you want, but didn't specify it...such as giving you the value of a string number without the VAL(), thus giving you a false sense of security, then later chokes on it... sigh
I guess a string var is the degenerate case of a one dimension, one element array.... Just call me a Flat-Lander.
--
Cheers, Steve

--- In ExcelVBA@yahoogroups.com, Derek Turner <g4swy@...> wrote:
>
> It's  StrReverse(Split(StrReverse(sFullFileName), SLASH)(0))
>
> Don't forget the (0).  which is the 0'th element of the Split array.
>
> OO methods have preceding dots in them. VB statements do not, mostly (?).
>
> DT +++
>
>
>
>
>
> >________________________________
> > From: noskosteve <noskosteve@...>
> >To: ExcelVBA@yahoogroups.com
> >Sent: Saturday, 9 June 2012, 3:34
> >Subject: [ExcelVBA] ReSOLVED: Opening a CSV file and populating cells just like Excel does
> >
> >
> > 
> >
> >
> >--- In ExcelVBA@yahoogroups.com, Derek Turner <g4swy@> wrote:
> >> Freefile gets the next available file number …people telling you that this is the proper way …
> >> hard coded magic numbers.
> >
> >Understood. Using your own (Open as #) FileNumbers vs. the system's sequential numbers.
> >
> >> Close by itself will close all open files (files opened with the 'Open' statement). Close 66 does not error if #66 is already closed or never opened.
> >
> >That is what I am familiar with in good ol'-fashion Basic. If you saw my CAT Workbooks, I use API calls into Kenel32 and system generated handles are used.
> >
> >AND... from the "Once You Understand it, the Initial Guidance Makes Sense" department (:-):
> >
> >> Note that the keyword 'Close' is both a VBA statement and also a method in the Windows Filesystem object. Do not confuse them.
> >
> >Ahhhh … If I knew how to 'not confuse' them …
> >
> >Uh… That was the issue. After trying several different creative, OO looking syntaxes, syntaxi, syntaxum…? I worked my way to:
> >
> >Windows(FileNameOnly).Close
> >
> >Where FileNameOnly = StrReverse(Split(StrReverse(sFullFileName), "\")
> >
> >… And all is well in the universe. ('Windows Object' was the clue I missed). After 8-10 years playing this OO syntax starts to maker sense, sort of.
> >
> >Thanks profusely, Steve, K9DCI
> >
> >
> >
> >
> >
>
> [Non-text portions of this message have been removed]
>

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar