Arrrrg! I now have a related question, but thanks both of you.
Derek's method is what I called "manual" parsing of the records and hoped to stay away from that, unless necessary, though I have successfully done it before - see below.
I couldn't immediately understand Dave's technique. So, rather than poking around and trying things to see if I could figure it out, I first tried to open the CSV as another Workbook, copy to an extra sheet in mine then close it, then scan the rows (Instead of the file) allowing me to "validate and modify" just swell. (I also enjoyed Derek's possible error areas and will keep that list close by - it all rings true.)
This worked fine by first hardcoding (Via Macro recording) the CSV Open/Close.
HOWEVER...
When I added the standard OPEN File dialog stuff for user capture of the FileName, now I can't close the CSV Workbook.
Macro recording gave me this for the hard coded close and it, of course, worked:
Windows("710ctcss.csv").Close
SO
I changed it to:
Windows(FileName).Close
Where: FileName = Application.GetOpenFilename(" bla
bla) (The regular Open Dialog)
However, that (Windows-Close) errors as an out of subscript range, most likely because the var FileName holds the full pathname, not just the file - shown in the recording version.
Looking at my previous adventures at _File_ reading (not Opening a Workbook), similar to the Way Derek suggests, I see that I got a file number with:
FileNum = FreeFile ' A system function. Don't recall where I saw this technique.
Then:
Close FileNum
Worked just fine (I think) for an Open File, but not for this Open Workbook. I get NO error, but the CSV-turned-Workbook doesn't get closed and FileNum appears to always be 1, not the typical random Handle type of thing.
The Object Browser shows the Function FreeFile as needing a "Range number"; I obviously got away without one (default ??)
Soooo
..
Using:
FileName = Application.GetOpenFilename(" TM-D710.csv data (*.csv), *.csv, bla
bla
bla"): Close
If FileName = "False" Then Exit Sub
Workbooks.Open FileName:=FileName
How to Close the Workbook ?
Regards (73), Steve
P.S. Derek, that's an interesting filename there in your example. You obviously have one of those new China radios and must be reverse engineering their file protocol. FYI: this code is for transferring Kenwood DM-D710 memories to a Kenwood TS-2000 via a "CAT workbook" I developed some years ago.
SEE:
Manage Radio Memories with an Excel Spreadsheet !
Click to tune. Click to capture Radio freq.
All Memories on one page. Cut, Copy, Paste, Print 'em...
For:
TM-D700 | TH-F6A & F7 | TS-2000 | Icom 706MkIIG
All PMs |Real-time & memories | Sat mems too | Loads Mem Tones!
NOT D710|Also Kenwood.fx Files|
More Details, Features and Downloads at:
http://k9dci.home.comcast.net/
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