Copying Data from User Selected Files Using GetOpenFilename

Ғылым және технология

Copying Data from User Selected Files Using GetOpenFilename
In this video I show how to use the GetOpenFilename function to allow users to select the file to open. Then
once the file is selected I show how to copy the data from this file to our current workbook. Most tutorials stop there but I will show you how to optimize this code so that if you are doing serious data analysis you have the fastest and cleanest code possible.
#ExcelVBA #VBAGetOpenFilename #VBAOptimizedCode
SUBSCRIBE TO THE CHANNEL: bit.ly/36hpTCY
DOWNLOAD THE SOURCE CODE FOR THIS VIDEO: bit.ly/3kYVdmb
(Note: If this page doesn't work make sure to turn off any popup blockers)
Related Training
The Excel VBA Handbook Course(TheExcelVBAHandbook.com)
Free Excel VBA Resources
Excel VBA Articles (excelmacromastery.com/vba-art...)
Useful VBA Shortcut Keys
========================
Debugging:
Compile the code: Alt + D + L OR Alt + D + Enter
Run the code from the current sub: F5
Step into the code line by line: F8
Add a breakpoint to pause the code: F9(or click left margin)
Windows:
View the Immediate Window: Ctrl + G
View the Watch Window: Alt + V + H
View the Properties Window: F4
Switch between Excel and the VBA Editor: Alt + F11
View the Project Explorer Window: Ctrl + R
Writing Code:
Search keyword under cursor: Ctrl + F3
Search the word last searched for: F3
Auto complete word: Ctrl + Space
Get the definition of the item under the cursor: Shift + F2
Go to the last cursor position: Ctrl + Shift + F2
Get the current region on a worksheet: Ctrl + Shift + 8(or Ctrl + *)
To move lines of code to the right(Indent): Tab
To move lines of code to the left(Outdent): Shift + Tab
Delete a Line: Ctrl + Y(note: this clears the clipboard)

Пікірлер: 51

  • @Excelmacromastery
    @Excelmacromastery Жыл бұрын

    Let me know in the comments if you have used GetOpenFilename.

  • @KRichardNicola

    @KRichardNicola

    Жыл бұрын

    Excellent, as always.

  • @onurtunc9468

    @onurtunc9468

    Жыл бұрын

    I m using ms access as db. Whenever i open workbook i let User select db and i also show User only see accdb default

  • @takahirom8023
    @takahirom8023Ай бұрын

    ありがとうございます。VBA初学者としてとても勉強になりました

  • @sasavienne
    @sasavienne Жыл бұрын

    Thank you so much for all your tips and explanations. I could really learn many things from your useful and interesting videos.

  • @cajinguy218
    @cajinguy218 Жыл бұрын

    Now I have to create a need to use this new knowledge! Thanks Paul for another useful tool for the toolbelt.

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Thanks,

  • @joaocustodio2094
    @joaocustodio2094 Жыл бұрын

    In each video I always learn something new. Thanks Paul.

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    You're welcome Joao

  • @user-yz5uh9th5z
    @user-yz5uh9th5z8 ай бұрын

    fantastic, saved me loads of time

  • @rahul7rock
    @rahul7rock Жыл бұрын

    Elegant explanation. It's always a valuable addition to my existing knowledge

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Glad you like it

  • @pauloandrecontab
    @pauloandrecontab Жыл бұрын

    Congratulations ! Excellent explanation!

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Thanks

  • @Matt-zp9jg
    @Matt-zp9jg Жыл бұрын

    This was awesome! Paul do you have plans on other coding subjects like Dax and Python? How you teach VBA, so many others would benefit on your teaching of other topics.

  • @ba3411
    @ba341110 ай бұрын

    Your videos are extremely useful. Thank you for sharing your knowledge. Can you please explain the xml features of excel and vba in a video?

  • @pauloandrecontab
    @pauloandrecontab Жыл бұрын

    Parabéns ! Excelente explicação!

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Thanks

  • @KM-co5mx
    @KM-co5mx Жыл бұрын

    This is a good one! 🤩

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Thanks

  • @arvindjaiswal4386
    @arvindjaiswal4386 Жыл бұрын

    Yes, i have used it in my project. I have created a new function to get the selected files from it

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Thanks for the feedback Arvind

  • @twiddle7125
    @twiddle7125 Жыл бұрын

    Probably would have been a good time to mention Application.ScreenUpdating, Application.DisplayAlerts, Application.EnableEvents, etc. Depending on the workbooks you are importing these become necessary to handle.

  • @Donkeys_Dad_Adam
    @Donkeys_Dad_Adam3 ай бұрын

    I learned the hard way to set the "Workbooks.Open" line to "UpdateLinks: =False" to avoid having an update external links dialog pop up when you open a file... I was opening files to read them and grab data, but a few had links to other workbooks and they would get stuck there.

  • @bayurukmanajati1224
    @bayurukmanajati1224 Жыл бұрын

    Excellent. We're almost there.... The classification algorithm with VBA. 😅

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Glad you like it

  • @iliesmeziani
    @iliesmeziani Жыл бұрын

    Thank you for this great video and for the information provided. Please can you provide us a The fastest method to Copying Data from User Selected Files with out open fils.

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    You can do using ADO. Check my channel for a video on it.

  • @corrywhite5025
    @corrywhite5025 Жыл бұрын

    Paul, thanks for the useful video. But the file is not available ehen I follow the link...

  • @optionmarathi
    @optionmarathi5 ай бұрын

    Please guide me to copy part of an excel file into notepad. For example, I want to copy data shown in A1:D5 of Sheet1 of an excel file into a new notepad on the desktop. Thanks in advance.

  • @kaanapadhiyar1143
    @kaanapadhiyar1143 Жыл бұрын

    How to create monthwise total in column with using vba

  • @neerajkatoch6724
    @neerajkatoch672428 күн бұрын

    If data needs to be copied from a sheet which have blank cells due to which current region didn't work there. How we do that

  • @LaloinLondon
    @LaloinLondon Жыл бұрын

    Hi Paul, What would you do if you want to copy the format of the source? Copy and paste? Regards, George

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Yes, that is correct

  • @LaloinLondon

    @LaloinLondon

    Жыл бұрын

    @@Excelmacromastery Thanks. Let me tell you that I took your advice about advanced filter as a speedy way to move data. I put into practice one of my reports and it flies!

  • @utha2665
    @utha2665 Жыл бұрын

    I have only just fond your channel, I have been out of VBA programming for a long time now, I was self-taught in the late 90s to about 2008. Since then I have had very little to do with programming as I left that job. Now, I'm wanting to get back into programming with Excel VBA, I have a few projects I want to have a go with, one thing that always did my head in was working with date formats in code, it drove me mad that anyone not using the mm/dd/yyyy format were doomed to live in pain. I have data that comes in as text, mostly with the time included and converting to the correct format to read as dd/mm/yyyy I'm finding hit and miss. Are there any existing videos you've discussed this on? Or is this a topic you have planned? Or is this not the right channel to be asking this question?

  • @AttackOnTyler

    @AttackOnTyler

    Жыл бұрын

    If your text is normal enough to have the first 8 characters be the date, you could always format(left(strVariable,8), "mm/dd/yyyy")

  • @Matt-zp9jg

    @Matt-zp9jg

    Жыл бұрын

    If the date is in there you can use regex to extract it.

  • @tonibottos
    @tonibottos Жыл бұрын

    Does It work also on Mac Osx ? Thanks!

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    It should but I haven't tried it.

  • @MandA.27
    @MandA.27 Жыл бұрын

    what if i want a copy of cell starting from a A16 i tried to this Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row data = sheet.Range("A16" & Lastrow) but it gave me an error from this Public Sub ArrayToRange(ByRef arr As Variant, rg As Range) rg.Resize(UBound(arr, 1) - LBound(arr, 1) + 1, UBound(arr, 2) - LBound(arr, 2) + 1) = arr End Sub sorry for my bad english. english is not my mother language

  • @utsavsharda
    @utsavsharda Жыл бұрын

    I have the same stuff in my Tools, I need ado to copy data in the same manner with the same formatting. can you do it?

  • @ricos1497

    @ricos1497

    Жыл бұрын

    You say "ado"? I assume that wasn't a mis-type, and you use the ADO method to extract without opening the workbook? Formatting can't be applied via ADO unfortunately. You would have to use the first example in the video, but paste with formatting, which is always a bit slower and uglier!

  • @utsavsharda

    @utsavsharda

    Жыл бұрын

    @@ricos1497 i currently copies data without ADO, i would prefer ADO it's way faster than this method as it opens and then closes file which in a huge data set creates a problem.

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    ADO won't copy formatting. Just data. I have videos on ADO - you can search for them on my channel.

  • @ricos1497

    @ricos1497

    Жыл бұрын

    @@utsavsharda yes, it is way faster, but then you don't get formatting! I always wondered if the formatting would be stored somewhere in the underlying XML for the Excel file, but I've never found it!

  • @petehiggins33
    @petehiggins33 Жыл бұрын

    At 1:36 I get a type mismatch error because 'filename' now contains a string so it can't be compared with a boolean value. Is this because my version of Excel is Office 2007?

  • @Excelmacromastery

    @Excelmacromastery

    Жыл бұрын

    Have you declared it as a variant?

  • @petehiggins33

    @petehiggins33

    Жыл бұрын

    @@Excelmacromastery Thank you, that fixed it. I was using your code download and running the mod001_basic module. It declares 'filename' as a string variable. The other modules declare it as a Variant. However, I didn't know that a Variant containing a string could be compared with a boolean value. You learn something new everyday, if you're not careful.

  • @khrishoman7149
    @khrishoman7149 Жыл бұрын

    I like what he has to teach, but he talks to fast for me to pick up what he's putting down.🤔

Келесі