File browser open twice

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
781
Office Version
  1. 365
Hi,

have the code below working only issue is when click import open path select file and it opens again, what I am doing now when open again click cancel and fine, but wonder why open twice the file dialog picker:

here is the code:

VBA Code:
Sub ImportRawData()
 
    Dim c           As Long
    Dim Col         As Variant
    Dim Filename    As String
    Dim Filepath    As Variant
    Dim rngBeg      As Range
    Dim rngEnd      As Range
    Dim rngDst      As Range
    Dim rngSrc      As Range
    Dim rowsize     As Long
    Dim wkbDst      As Workbook
    Dim wkbSrc      As Workbook
    Dim vFile
    Dim fd As FileDialog
    Dim newFile As String, fName As String

Set fd = Application.FileDialog(msoFileDialogFilePicker)
' Change initial folder as needed or store it in a cell and reference that
fd.InitialFileName = "W:\NCL\NAVCOM\AP63A\NAVCOM\AP63A\VANCOUVER\IMPORT FILES"

'fd.AllowMultiSelect = True
FilePicked = fd.Show

    

    vFile = Application.GetOpenFilename("CSV Files(*.csv),*.csv", , "please select a file", MultiSelect:=False)

         Set wkbDst = ThisWorkbook
        Set rngDst = wkbDst.Worksheets("EFT Summary").Range("A5:F5")
        
        Filepath = "C:\Users\jose.rossi\AppData\Roaming\Microsoft\Templates\Primus Batch EFT.....xltm"
        Filename = "apcbtclz.csv"
        
        On Error Resume Next
            Set wkbSrc = Workbooks(Filename)
            If Err = 9 Then
                If Filepath <> "" Then ChDir Filepath Else ChDir ThisWorkbook.Path
                'Filename = Application.GetOpenFilename("Excel Workbooks, *.xlsx")
                If Filename = "False" Then Exit Sub
                Set wkbSrc = Workbooks.Open(Filename)
            End If
        On Error GoTo 0
        
        ' Clear previous data.
        'rngDst.Resize(rngDst.Parent.UsedRange.Rows.Count).ClearContents
        
        ' Import the data.
        With wkbSrc.Worksheets("apcbtclz").UsedRange
            ' Step through the source data columns.
            For Each Col In Array("AW", "BO", "BB", "AX", "X", "CH")
            
                        
            
            
            
                ' Data starts on row 1.
                Set rngBeg = .Parent.Cells(1, Col)
                
                ' Find the row where the data ends in this column.
                Set rngEnd = .Parent.Cells(Rows.Count, Col).End(xlUp)
                
                ' Number of rows in this column.
                rowsize = rngEnd.Row '- rngBeg.Row
                
                If rowsize > 0 Then
                    Set rngSrc = .Parent.Range(rngBeg, rngEnd)
                    rngDst.Offset(0, c).Resize(rowsize, 1).Value = rngSrc.Value
                End If
                
                ' Increment the column offset.
                c = c + 1
                If c = 6 Then Let c = 7
            Next Col
            
        End With
     
wkbSrc.Close (True)

End Sub

thank you
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
These are basically the same thing

fd.Show

Application.GetOpenFilename

Do one or the other but not both unless you want 2 dialogs.
 
Upvote 0
Solution
that was it, commented out one of the and worked.

Thank you,
The marked solution has been switched accordingly.

@josros60 - in your future questions, please mark the post that answered your question instead of your feedback post to help the future readers.
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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