Forum

Application.FileDia...
 
Notifications
Clear all

Application.FileDialog(msoFileDialogOpen) opens folder twice

3 Posts
2 Users
0 Reactions
90 Views
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Morning All,

I have database that upload data from a folder after when select a specific file from folder. When I select the folder, the Dialog folder box pops back up and you have to select the file again for the data to be uploaded. The following code below

Sub Get_Data_From_File1() '.....NSWTA SITE

MySheet3.Activate

Dim sFolder As String
Dim OpenBook As Workbook
' Open the select folder prompt
With Application.FileDialog(msoFileDialogOpen) ' THIS OPEN THE DIALOG BOX BUT OPENS TWICE???????????????????
If .Show = False Then Exit Sub ' IF USEWR CANCELS THE EXIT DIALOG BOX
Sheets("SiteFinder").Unprotect Password:="Online"
DeleteCurrentRegion2
.InitialFileName = "H:PROJECT-OPSNSW WarehouseNSWTA Inventory Listing"
If .Show = -1 Then ' if OK is pressed
sFolder = .SelectedItems(1)
Application.ScreenUpdating = True
End If
End With
Application.ScreenUpdating = False
Set OpenBook = Application.Workbooks.Open(sFolder, Password:="Online")
OpenBook.Sheets(1).Range("A1:J" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Copy
ThisWorkbook.Worksheets("SiteFinder").Cells(Rows.Count, "C").End(xlUp).Offset(3, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
OpenBook.Close False
InsertTableArray1
Range("A1").Select
Protect_ShapesRange
End Sub

Its only after when the dialog box opens twice and select the file imports the data

Can someone tell me why the dialog box opens twice

Unfortunately I cannot supply you my database because it wont work outside the network!

Thanks

Steve

 
Posted : 22/11/2021 8:34 pm
(@catalinb)
Posts: 1937
Member Admin
 

Look again at your code, you will see that ".Show" is found twice in your code. If you use .Show 10 times, it will display the dialog 10 times.

 
Posted : 22/11/2021 11:51 pm
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Yes I see Catalin!

What I have done now is

Sub Get_Data_From_File1() '.....NSWTA SITE
MySheet3.Activate
Dim sFolder As String
Dim OpenBook As Workbook
' Open the select folder prompt
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = "H:PROJECT-OPSNSW WarehouseNSWTA Inventory Listing"
If .Show = -1 Then ' if OK is pressed
sFolder = .SelectedItems(1)
Else ' IF USER CANCELS THEN EXIT THE SUB THEN MESSAGE
MsgBox ("ITS EITHER BECAUSE THE SITE HAS NOT BEEN RECEIPTED")
Exit Sub
Application.ScreenUpdating = True

End If
Sheets("SiteFinder").Unprotect Password:="Online"
DeleteCurrentRegion2
End With
Application.ScreenUpdating = False

Set OpenBook = Application.Workbooks.Open(sFolder, Password:="Online")
OpenBook.Sheets(1).Range("A1:J" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Copy

ThisWorkbook.Worksheets("SiteFinder").Cells(Rows.Count, "C").End(xlUp).Offset(3, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
OpenBook.Close False
InsertTableArray1
Range("A1").Select
Protect_ShapesRange

End Sub

 

All good thanks for that help

 

Steve

 
Posted : 23/11/2021 5:39 pm
Share: