Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
tod tod is offline
external usenet poster
 
Posts: 114
Default 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.
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i open the write protected excel file? Vipul Shukla Excel Discussion (Misc queries) 1 November 7th 08 08:33 AM
Saving a copy of excel file in macro but have it auto write pano Excel Worksheet Functions 4 March 27th 07 11:54 PM
HOW TO OPEN A WRITE PROTECTED FILE (USB) Wendyanne Excel Discussion (Misc queries) 2 August 16th 06 01:38 PM
Write Procedure With Logic Test To Open File From Given Directory Carl Bowman Excel Programming 4 February 12th 05 02:15 AM
Open file to write and read at the same time Tom Ogilvy Excel Programming 2 September 22nd 03 01:10 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"