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: 18
  • two.PNG
    two.PNG
    46.5 KB · Views: 17

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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