How to browse import file .xlsm and create new sheet from .xlsm is imported?

oshi1998

New Member
Joined
Jan 13, 2021
Messages
7
Platform
  1. Windows
Hello everyone, Sorry, My english isn't that good. I'm still practicing.
This is my second thread. I need to know source code for this.
step1.JPG

Step 1 : user click import file button and show dialog for browse file .xlsm (macro file)
Step 2 : import file already and bring worksheet from .xlsm is imported to create as new sheet in current file.
step2.JPG


*** If import .xlsm file already. can user use function from .xlsm file is imported?
I want user can use it also. Help me pls!
Thanks for help
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You can attach this to a Form Controls command button.

VBA Code:
Sub t()
Dim fName As String, wb As Workbook, sh As Worksheet
fName = Application.GetOpenFilename("Excel Files (*.xlsm), *.xlsm")
    If fName <> False And fName <> "" Then
        Set wb = Workbooks.Open(fName)
        wb.Sheets(1).Copy After:=ThisWorkbook.Sheets(Thisworkbook.Sheets.Count)
        wb.Close False
    End If
End Sub
 
Upvote 0
Solution
You can attach this to a Form Controls command button.

VBA Code:
Sub t()
Dim fName As String, wb As Workbook, sh As Worksheet
fName = Application.GetOpenFilename("Excel Files (*.xlsm), *.xlsm")
    If [B][COLOR=rgb(184, 49, 47)]fName <> False[/COLOR][/B] And fName <> "" Then
        Set wb = Workbooks.Open(fName)
        wb.Sheets(1).Copy After:=ThisWorkbook.Sheets(Thisworkbook.Sheets.Count)
        wb.Close False
    End If
End Sub
Excellent! but i need delete "fName <> False" out
because excel said : "runtim-error 13 type missmatch"
Anyway It's work !! thank you very much
 
Upvote 0
It could be a problem with the version of Excel you are using. The code runs without error on my Win 10, xl2013 version. The statement is in there to avoid an error 8, when the user clicks cancel or exits the dialog box without seledting a file. So not sure how to fix it other than delete the If Then statement and hope the user always selects a file. You can try this and see if it still errors:

VBA Code:
Sub t()

Dim fName As String, wb As Workbook, sh As Worksheet
fName = Application.GetOpenFilename("Excel Files (*.xlsm), *.xlsm")
    If fName <> "False" Then
        Set wb = Workbooks.Open(fName)
        wb.Sheets(1).Copy After:=ThisWorkbook.Sheets(Thisworkbook.Sheets.Count)
        wb.Close False
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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