| | |
FileOpen Dialog without using Common Dialog Control
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2006
Posts: 39
Reputation:
Solved Threads: 0
Good Morning guys,
Can someone please tell me how to insert a fileopen dialog in VB? What I want is when the user clicks on a button, the program takes them to a particular directory or folder, that way they will be able to select files on their own from that folder.
For some reason, I do not have the CommonDialog control which should be under "Additional Controls." Is there a way I can install the commondialog control into my system? Please let me know.
If there is a thread that already exist in this forum regarding opening the dialog box, please send it to me. Thank you very much for your anticiapted cooperation.
Ini
Can someone please tell me how to insert a fileopen dialog in VB? What I want is when the user clicks on a button, the program takes them to a particular directory or folder, that way they will be able to select files on their own from that folder.
For some reason, I do not have the CommonDialog control which should be under "Additional Controls." Is there a way I can install the commondialog control into my system? Please let me know.
If there is a thread that already exist in this forum regarding opening the dialog box, please send it to me. Thank you very much for your anticiapted cooperation.
Ini
in a module:
Then call it with a form like:
It's easy enough to modify anything you need to change (such as the initdir) openfile UDT
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' /* Code Taken From: http://forums.devx.com/showthread.php?t=148627 */ Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long Public Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type public Function SelectFileOpenDialog() Dim strTemp, strTemp1, pathStr As String Dim i, n, j As Long Dim OpenFile As OPENFILENAME Dim lReturn As Long Dim sFilter As String Dim Fname As String OpenFile.lStructSize = Len(OpenFile) sFilter = "Text Files (*.txt)" & Chr(0) & "*.TXT" & Chr(0) OpenFile.lpstrFilter = sFilter OpenFile.nFilterIndex = 1 OpenFile.lpstrFile = String(257, 0) OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1 OpenFile.lpstrFileTitle = OpenFile.lpstrFile OpenFile.nMaxFileTitle = OpenFile.nMaxFile OpenFile.lpstrInitialDir = "C:\" OpenFile.lpstrTitle = "Select File" OpenFile.flags = 0 lReturn = GetOpenFileName(OpenFile) If lReturn = 0 Then MsgBox "You didn't select any file" Else 'MsgBox "The user Chose " & Trim(OpenFile.lpstrFile) Fname = Trim$(OpenFile.lpstrFileTitle) ' copy the filename to "Fname" n = FileLen(OpenFile.lpstrFile) 'length of the file End Function
Then call it with a form like:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Form_Load() SelectFileOpenDialog End Sub
It's easy enough to modify anything you need to change (such as the initdir) openfile UDT
•
•
Join Date: May 2006
Posts: 39
Reputation:
Solved Threads: 0
Thank you for the info; when I tried it, it opened the dialog box of teh particular folder, but when I clicked on the file to open nothin happened.
Do you know how I can install a common dialog control into my system? Because if I had that, my program will be much easier. Also the code you gave me is to long, I appreciate it very much but do you have access to a shorter code?
Ini
Do you know how I can install a common dialog control into my system? Because if I had that, my program will be much easier. Also the code you gave me is to long, I appreciate it very much but do you have access to a shorter code?
Ini
not without using the commondialog control..... you can download the .ocx from just about anywhere..... once you have it downloaded, place it in the windows\system32 folder, and click start, run, regsvr32 c:\windows\system32\comdlg32.ocx, and hit enter..... then you should have it on the system. I personally suggest the API method over the ocx, though, since the api method is standalone, and doesn't require such dependancies.... but whatever boats your float.
http://www.ascentive.com/support/new...e=COMDLG32.OCX
http://www.ascentive.com/support/new...e=COMDLG32.OCX
•
•
Join Date: May 2006
Posts: 39
Reputation:
Solved Threads: 0
This is what I have; do you think you could figure a way I could specify which directory I want?
Thanks.
Ini
___________________________________________________
Dim UF As Variant
UF = Application.GetOpenFileName(FileFilter:="Excel workbooks(*.xls), *.xls", Title:="Excel Files")
If UF = False Then
Exit Sub
Else
If UF <> "" Then
Workbooks.Open Filename:=UF
End If
End If
Thanks.
Ini
___________________________________________________
Dim UF As Variant
UF = Application.GetOpenFileName(FileFilter:="Excel workbooks(*.xls), *.xls", Title:="Excel Files")
If UF = False Then
Exit Sub
Else
If UF <> "" Then
Workbooks.Open Filename:=UF
End If
End If
•
•
Join Date: May 2006
Posts: 39
Reputation:
Solved Threads: 0
Please could you help me write code? Thanks.
Also I have another one that works using FileDialog, as the top code, it opens the dialog but will not open the file. please make the right corrections for me (code).
Dim FD As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set FD = Application.FileDialog(msoFileDialogFilePicker)
FD.Title = "Choose file to open"
FD.InitialFileName = "H:\"
FD.Show
Ini
Also I have another one that works using FileDialog, as the top code, it opens the dialog but will not open the file. please make the right corrections for me (code).
Dim FD As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set FD = Application.FileDialog(msoFileDialogFilePicker)
FD.Title = "Choose file to open"
FD.InitialFileName = "H:\"
FD.Show
Ini
I dunno, I've never used the FileDialog object. It's not a standard part of VB6, and I dunno where you got it. you should be able to call a property that gets set when the file is selected, maybe something like FD.Filename, but since I don't use it, I wouldn't know....
In the first example, it looks like you are trying to open the file in excel.... which would be something more like:
In the first example, it looks like you are trying to open the file in excel.... which would be something more like:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
dim objExcel dim objworkbook Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open(file_from_dialogbox_here) objExcel.visible = true set objExcel = nothing set objWorkbook = nothing
![]() |
Similar Threads
- Common Dialog (Visual Basic 4 / 5 / 6)
- vb6/common dialog/access db (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: tabledef in ado
- Next Thread: changing menu control
Views: 15069 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






