ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I write an Excel macro to open a file using the CommonDial. (https://www.excelbanter.com/excel-programming/326420-how-do-i-write-excel-macro-open-file-using-commondial.html)

Lynn

How do I write an Excel macro to open a file using the CommonDial.
 
I am writing a macro. I have one spreadsheet open. I want the user to be
prompted to open a second spreadsheet by opening the Open Dialog Box and
having the user click on the file they want to open.
VB has a ShowOpen command, but I am having trouble using it with excel.

tod

How do I write an Excel macro to open a file using the CommonDial.
 
The code would look like this:

'Prompt user for Excel file to open
MsgBox "Choose the data file for this report from the
following dialog.", vbOKOnly
Application.Dialogs.Item(xlDialogOpen).Show

You would attach this code to either a button or command
bar, etc.

For example, you could do this:

Sub OpenFile
'Prompt user for Excel file to open
MsgBox "Choose the data file for this report from the
following dialog.", vbOKOnly
Application.Dialogs.Item(xlDialogOpen).Show
End Sub

Then right click on the toolbar and choose the Forms
toolbar. From there choose the command button. When you
draw the button on the screen it will ask you to assign a
macro. Choose your OpenFile macro.

tod

-----Original Message-----
I am writing a macro. I have one spreadsheet open. I

want the user to be
prompted to open a second spreadsheet by opening the

Open Dialog Box and
having the user click on the file they want to open.
VB has a ShowOpen command, but I am having trouble using

it with excel.
.


Tom Ogilvy

How do I write an Excel macro to open a file using the CommonDial.
 
In Excel,

Dim fName as Variant
fName = Application.GetOpenFileName( _
FilterIndex:="Excel Files (*.xls),*.xls")
if fName = False then
msgbox "You hit cancel"
exit sub
else
set wkbk = workbooks.Open(fName)

End if



--
Regards,
Tom Ogilvy


"Lynn" wrote in message
...
I am writing a macro. I have one spreadsheet open. I want the user to be
prompted to open a second spreadsheet by opening the Open Dialog Box and
having the user click on the file they want to open.
VB has a ShowOpen command, but I am having trouble using it with excel.





All times are GMT +1. The time now is 02:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com