Hello,
For a project I actually use a macro to export data from one unopen workbook sheet to the actual xlsm workbook sheet.
I recently found a problem on the export sheet, this sheet has to be updated every single week but probel the change the name of the sheet changes every week.
But on my export code I need to specify the actual sheet name, my question is : Is there any way to export data from the selected workbook without specifying the name of the sheet (generally is the first sheet)
This is the code :
I will appreciate some help
Remark : The unopen workbook is a csv file which is weekly uploaded on the database so The name of the workbook and the name of the first sheet is the same.
For a project I actually use a macro to export data from one unopen workbook sheet to the actual xlsm workbook sheet.
I recently found a problem on the export sheet, this sheet has to be updated every single week but probel the change the name of the sheet changes every week.
But on my export code I need to specify the actual sheet name, my question is : Is there any way to export data from the selected workbook without specifying the name of the sheet (generally is the first sheet)
This is the code :
VBA Code:
Public Sub Export()
Dim Export_Wrk As Workbook
Dim Main_Wrk As Workbook
Dim WaySheet As String
With Application.FileDialog(msoFileDialogFilePicker)
If .Show <> 0 Then
WaySheet = .SelectedItems(1)
Set Export_Wrk = Workbooks.Open(WaySheet)
Set Main_Wrk = Workbooks("Template.xlsm")
Export_Wrk.Sheets("export_week1").Activate ' I have to specify the name of the sheet
Last_ligne = Export_Wrk.Sheets("export_week1").Cells(Rows.Count, "A").End(xlUp).Row ' I have to specify the name of the sheet
Main_Wrk.Sheets("export_week1").Range("A1:AG" & Last_ligne).Copy ' I have to specify the name of the sheet
Main_Wrk Sheets("Export_1").Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Export_Wrk.Close
Else
MsgBox "You have canceled the transfert"
Exit Sub
End If
End With
End Sub
I will appreciate some help
Remark : The unopen workbook is a csv file which is weekly uploaded on the database so The name of the workbook and the name of the first sheet is the same.
Last edited: