Excel Open Dialogue Box

Excel Open Dialogue Box

Anonymous
Not applicable
318 Views
1 Reply
Message 1 of 2

Excel Open Dialogue Box

Anonymous
Not applicable
hi, All
I have seen that below is a routine which is used to open a sepecific file from Excel but i want in a different way like i do not the file name and i want the same open dialogue box to open and select a desired file.
can any one tell me how.
thanks

Dim Excelobj As Excel.Application
Dim wbkobj As Workbook
Dim shtobj As Worksheet
On Error Resume Next
UserForm1.Hide
Err.Clear
Set Excelobj = GetObject(, "Excel.Application")
If Err 0 Then
MsgBox "couldnot start excel", vbExclamation
End
End If
End If
Excelobj.Visible = True
Set wbkobj = workbooks.Open(FileName:="C:\Dwg\REGISTER.xls")
Set shtobj = Exceobj.worksheets(1)
UserForm1.Show
End Sub
0 Likes
319 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Using the Dialog Object
The following example runs the built-in Open dialog box (File menu). The Show method returns True if Microsoft Excel successfully opens a file; it returns False if the user cancels the dialog box.

Example
dlgAnswer = Application.Dialogs(xlDialogOpen).Show
'dlgAnswer = Excelobj .Dialogs(xlDialogOpen).Show

or

GetOpenFilename Method
Displays the standard Open dialog box and gets a file name from the user without actually opening any files.

Example
This example displays the Open dialog box, with the file filter set to text files. If the user chooses a file name, the code displays that file name in a message box.

fileToOpen = Application _
.GetOpenFilename("Text Files (*.xls), *.xls")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
'Set wbkobj = workbooks.Open(FileName:=fileToOpen)
End If
0 Likes