![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 14
|
Hi,
I am trying to create a macro to import a data file into an excel sheet. I was able to record a macro,but i was only able to import the same file each time. Can anyone help me create a macro to open a file popup menu such that i can choose the file to be imported. I can send you my recorded macro code if you need. One more thing, this is my first encounter with VBasic. Please help me........ Thank you. |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Posts: 85
|
try this:
sub import () dim fileToOpen as String dim PasteOnThisWB as string PasteOnThisWB = Activeworkbook.name fileToOpen = Application.GetOpenFilename("Microsoft Excel Files (*.xls), *.xls") If fileToOpen <> False Then Workbooks.Open fileToOpen Else Exit Sub End If cells.select selection.copy workbooks(PasteOnThisWB).select Range("A1).select Selection.Paste Workbooks.Close fileToOpen Savechanges := False end Sub |
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Posts: 14
|
This helped me a bit, But i need to import a data file not open new file,your code opens an excel file.
Can you help me with the Import thing. Thanks Raju |
|
|
|
|
|
#4 |
|
New Member
Join Date: May 2002
Posts: 14
|
ThIs isn't working.there is an error at the IF statement....
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Posts: 85
|
What does error say? I just used that exact code in a macro
|
|
|
|
|
|
#6 |
|
New Member
Join Date: May 2002
Posts: 14
|
Run-time error '13':
Type Mismatch I changed the parameters to "Allfiles *.* instead of "Microsoft Excel Files*.xls" |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Mar 2002
Location: England, UK.
Posts: 526
|
what data file, a text file?
If so, is the data in the text file seperated by a comma, space or something or is it all 'stuck' together? RET79 [ This Message was edited by: RET79 on 2002-05-02 13:25 ] |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Apr 2002
Posts: 85
|
Sorry!
Dim fileToOpen as variant that should fix runtime |
|
|
|
|
|
#9 |
|
New Member
Join Date: May 2002
Posts: 14
|
Its a text file Seperated by a commas
|
|
|
|
|
|
#10 |
|
New Member
Join Date: May 2002
Posts: 14
|
Thanks
the Variant thing helped but was not able file in a table form. I think it has something to do with the comma delimiter. and how can i make the file to be open in the next sheet. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|