Import data from two workbooks with similar names
Thanks Jim,
That works great. I thought it had something to do with the "Len" command
but I was telling it 5 characters going from the decimal and it looks like
you are stating 9 characters from right to left starting at the "s" in .xls
and including the decimal. Anyway this works just the way I need it to.
Now I need to look at having it run ALL the files and name the files
according to the names of the original files with one execution of the macro
button. I will work on this.
Thanks for your help,
--
John S. Walker
"Jim Cone" wrote:
John,
Things got a whole lot simpler.
Something similar to the following ought to do it.
Jim Cone
San Francisco, USA
'--------------------------------------------
Sub Test()
Dim varFileToOpen As Variant
varFileToOpen = Application.GetOpenFilename
'Open Item file (the cancel button returns False)
If varFileToOpen < False Then
Workbooks.Open varFileToOpen
'process workbook
Else
Exit Sub
End If
'Open Wire file...
varFileToOpen = Left$(varFileToOpen, Len(varFileToOpen) - 9) & "-Wire.xls"
Workbooks.Open varFileToOpen
'process workbook
End Sub
'----------------------------------
"John"
wrote in message
Jim,
I don't understand the programming behind this, sorry. I have placed this
into the program and have tried it various ways but continue to have errors.
Maybe i was not clear on what I am doing. I select one file with a name
that, as an example, had 4 numbers and then -item. The actual file name
could be PE123456-item or could be 15367827-item or 12345678_fwd_lp-item and
the matching file to the -item file would be the same name but with "-wire".
There will be multiple files from 2 to 100 (and more) in the same location as
my QIC_AM program. I select the ********-item file and it opens and I copy
the content. Then I select the second file ********-wire and it opens and I
copy the content. The two files will then close and my program will calculate
the data. When it is done, I save the new file and QIC_AM asks if I want to
run another set of files. If I select yes, I then repeat the process.
I would like to be able to programmatically have QIC_AM recognize the
********-wire file to match the ********-item that has already been opened
and copied.
Sorry for my confusion. Still would appreciate help, thanks.
--
John S. Walker
|