Macro to import file

braju

New Member
Joined
May 1, 2002
Messages
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.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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
 
Upvote 0
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
 
Upvote 0
Run-time error '13':
Type Mismatch
I changed the parameters to "Allfiles *.* instead of "Microsoft Excel Files*.xls"
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,080
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top