Export data from a unopen file CSV using msoFileDialogFilePicker but data are not correctly placed

Gwhaou

Board Regular
Joined
May 10, 2022
Messages
78
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello,

I use this code to export a data from the sheet_1 from a unopen file to the actual workbook by using a macro

This is the code :

VBA Code:
Public Sub Export()




Dim Wrkb_1 As Workbook
Dim Wrkb_2 As Workbook

Dim Way As String

    With Application.FileDialog(msoFileDialogFilePicker)
    
        If .Show <> 0 Then
        
            Way = .SelectedItems(1)
                
            Set Wrkb_1 = Workbooks.Open(Way)
            Set Wrkb_2 = Workbooks("Template_File.xlsm")

            Wrkb_1.Sheets("export_week1").Activate
            Last_ligne = Wrkb_1.Sheets("export_week1").Cells(Rows.Count, "A").End(xlUp).Row
            Wrkb_1.Sheets("export_week1").Range("A1:AG" & Last_ligne).Copy

    
            Wrkb_2.Sheets("Export_1").Activate
            Range("A1").Select
            ActiveSheet.Paste
    

            Application.CutCopyMode = False
            Wrkb_1.Close
        
        Else
            MsgBox "Mission failed"
            Exit Sub
        
        End If
        End With
     
End Sub

My problem when I select a normal xlsx file it works perfectly, now the format of the file change in CSV because we are exporting data weekly from your website.
I tried the code but the placement are not good.
U can see that on the images :

I would like some help.
 

Attachments

  • one.PNG
    one.PNG
    45.4 KB · Views: 15
  • two.PNG
    two.PNG
    46.5 KB · Views: 14

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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