How to program a command Button to prompt the user to select a file and export it in Excel
Question:
I am completely new to macros and VBA. want help creating a command button (ActiveX control) to prompt the user to select an Excel workbook and export it to a tab specified in the current workbook. Please help.
Thanks and regards, Amey ..
Answers:
I am completely new to macros and VBA. want help creating a command button (ActiveX control) to prompt the user to select an Excel workbook and export it to a tab specified in the current workbook. Please help.
Thanks and regards, Amey ..
Answers:
You can use this code to select the file.
Then to import the content to a tabfindPath = Application.GetOpenFilename( _ Title:="Select file", _ filefilter:="Excel files (*.xlsx), *.xlsx, Excel files 97-93 (*.xls), *.xls", _ MultiSelect:=False) If (findPath = "false") Then MsgBox ("an error occurred. cancel operation....") End End If Workbooks.Open Filename:=findPath WB = ActiveWorkbook.Name
Later select the worksheet you want and paste it. And close itDim ws1 As Worksheet Set ws1 = ThisWorkbook.Worksheets(1) '1 is the first one. you can do a loop ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
Workbooks(WB).Close SaveChanges:=False
Commentaires
Enregistrer un commentaire