How to display common file dialogs?

Posted: 11-16-2005, 10:32 PM

Greetings. I'm using Office X on a G4 desktop with OS version 10.4.3.
I have some VBA macros in PowerPoint which I know to work well on
Windows, and now I'm trying to use them on the Mac as well. VBA in
general appears to work fine, but some of my macros don't.

The problem appears to be with common file dialogs. For example, in a
macro on Windows I can do something like this:

Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Show

....which causes a 'File Open' dialog to appear, and everything's great.
The trouble is, Application.FileDialog doesn't seem to even exist on
the Mac -- so what do I do? I can't believe there aren't standard
dialog types in MacOS, so there has to be some way to access them.

Sorry if this is too elementary -- I've looked in the help file and
other places, all to no avail, I'm afraid. Maybe I'm just not
searching for the right terms. Any help would be enormously
appreciated.

Thanks!
-DH

How to display common file dialogs?


Reply With Quote

Responses to "How to display common file dialogs?"

Steve Rindsberg
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-17-2005, 05:28 AM
Mac PPT's VBA is still at version 5 (ie, equivalent to Office 97), so a number
of things won't fly. Enums, events ...

I don't recall when .FileDialog was ... erm ... revealed on the Windows side.
It's in PPT97 and PPT2000 but hidden. Doesn't appear in PPTX, hidden or not.

I suspect you'll need to create your own dialog (user form) or learn
Applescript.

In article <1132180330.056048.61860@g14g2000cwa.googlegroups. com>, wrote:
> Greetings. I'm using Office X on a G4 desktop with OS version 10.4.3.
> I have some VBA macros in PowerPoint which I know to work well on
> Windows, and now I'm trying to use them on the Mac as well. VBA in
> general appears to work fine, but some of my macros don't.
>
> The problem appears to be with common file dialogs. For example, in a
> macro on Windows I can do something like this:
>
> Dim fd As FileDialog
> Set fd = Application.FileDialog(msoFileDialogOpen)
> fd.Show
>
> ....which causes a 'File Open' dialog to appear, and everything's great.
> The trouble is, Application.FileDialog doesn't seem to even exist on
> the Mac -- so what do I do? I can't believe there aren't standard
> dialog types in MacOS, so there has to be some way to access them.
>
> Sorry if this is too elementary -- I've looked in the help file and
> other places, all to no avail, I'm afraid. Maybe I'm just not
> searching for the right terms. Any help would be enormously
> appreciated.
>
> Thanks!
> -DH
>
================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================


Reply With Quote
Jim Gordon MVP
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-17-2005, 05:49 AM
Hi,

FileDialog is probably a new command introduced in Visual Basic for
Applications version 6. Office on the Mac supports VBA up to version 5.

However, it is possible to display the File Open dialog box
programmatically in VBA on the Mac.

One way is to use VBA to click the File Open button on the standard
toolbar. Check the Excecute command for command bar buttons in help for
an example.

A better way is to create a temporary toolbar, put the File Open button
on it, then use the execute command to display the File Open dialog box.
This way if someone has customized their standard toolbar it will still
work.

Here's some code I use to create a temporary toolbar called Animate Object:

' Create the temporary toolbar and add two command buttons to it
Set TempBar = CommandBars.Add(Name:="AnimateObject")
TempBar.Visible = True

Application.CommandBars("AnimateObject").Controls. Add
Type:=msoControlButton, Id:= _
2746, Before:=1
Application.CommandBars("AnimateObject").Controls. Add
Type:=msoControlButton, Id:= _
750, Before:=2

'Set TempBarButton =
CommandBars("AnimateObject").Controls.Add(Type:=ms oControlButton)
'With TempBarButton
'.FaceId = 2746
'.Visible = True
'End With
Set MyBar = CommandBars("AnimateObject")
With MyBar
.Height = 0
.Width = 50
.RowIndex = 3
.Position = msoBarTop
.Visible = False
End With

Notice that the FaceID number and the msoControlButton ID are the same
number. You can find those numbers by finding and downloading FACEID.XLS
(it's available from several MVP web sites - find it with Google). The
number for File Open dialog box is 23.

To get rid of the temporary command bar:
Application.CommandBars("AnimateObject").Delete

To click the first button on the command bar
Application.CommandBars("AnimateObject").Controls( 1).Execute

To click the second it would be
Application.CommandBars("AnimateObject").Controls( 2).Execute

Just to make sure everything worked OK I just successfully tested with
this code:

Sub tempbar()
' Create the temporary toolbar and add two command buttons to it
Set test = CommandBars.Add(Name:="test")
test.Visible = True

Application.CommandBars("test").Controls.Add
Type:=msoControlButton, Id:= _
23, Before:=1
End Sub

Sub click()
Application.CommandBars("test").Controls(1).Execut e
End Sub

-Jim
--
Jim Gordon
Mac MVP
MVP FAQ
<http://mvp.support.microsoft.com/default.aspx?scid=fh;EN-US;mvpfaqs>


grendel99@yahoo.com wrote:
> Greetings. I'm using Office X on a G4 desktop with OS version 10.4.3.
> I have some VBA macros in PowerPoint which I know to work well on
> Windows, and now I'm trying to use them on the Mac as well. VBA in
> general appears to work fine, but some of my macros don't.
>
> The problem appears to be with common file dialogs. For example, in a
> macro on Windows I can do something like this:
>
> Dim fd As FileDialog
> Set fd = Application.FileDialog(msoFileDialogOpen)
> fd.Show
>
> ...which causes a 'File Open' dialog to appear, and everything's great.
> The trouble is, Application.FileDialog doesn't seem to even exist on
> the Mac -- so what do I do? I can't believe there aren't standard
> dialog types in MacOS, so there has to be some way to access them.
>
> Sorry if this is too elementary -- I've looked in the help file and
> other places, all to no avail, I'm afraid. Maybe I'm just not
> searching for the right terms. Any help would be enormously
> appreciated.
>
> Thanks!
> -DH
>
Reply With Quote
grendel99@yahoo.com
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-17-2005, 06:06 PM
Thanks for your reply, Jim, that was very good advice. I've succeeded
in making the File Open dialog box appear using your technique, but now
I need to return the filename(s) of the files chosen in the dialog back
to the calling function. For example, in Windows I could do this:

Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Show
Dim szFile as String
szFile = fd.SelectedItems.Item(1)

....thereby storing in szFile the name of the file selected in the
dialog. What would be the corresponding technique on the Mac? (I'm
fearful you'll tell me there isn't one, since we're opening the dialog
through a command bar.) BTW, this business of Mac's VBA only being
version 5 is bizarre; surely Microsoft has the power to port VB 6...

Many thanks!
- DH

Reply With Quote
Steve Rindsberg
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-17-2005, 08:18 PM
In article <1132250763.916330.215310@g49g2000cwa.googlegroups .com>, wrote:
> Thanks for your reply, Jim, that was very good advice. I've succeeded
> in making the File Open dialog box appear using your technique, but now
> I need to return the filename(s) of the files chosen in the dialog back
> to the calling function. For example, in Windows I could do this:
>
> Dim fd As FileDialog
> Set fd = Application.FileDialog(msoFileDialogOpen)
> fd.Show
> Dim szFile as String
> szFile = fd.SelectedItems.Item(1)
>
> ....thereby storing in szFile the name of the file selected in the
> dialog. What would be the corresponding technique on the Mac? (I'm
> fearful you'll tell me there isn't one, since we're opening the dialog
> through a command bar.)
Ugly ugly kluge, but once it returns from the file open dialog, a file should
be open. You could get its fullname and close it if you don't actually want it
open. Did I mention ugly? If not, I meant to.
> BTW, this business of Mac's VBA only being
> version 5 is bizarre; surely Microsoft has the power to port VB 6...
It may be more a question of how much demand there is for it as compared to the
demand for other features. I suspect "other features" wins.

================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================


Reply With Quote
Paul Berkowitz
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-18-2005, 12:39 AM
Or you could simply use the MacScript function:

Dim FilePath As String

FilePath = MacScript("(choose file) as string")


That will open an OS Open dialog, to let you choose the file you want to
open, and will return the result as a Mac colon-delimited string (such as
"Macintosh Hard Disk:Folder 1:Folder 2:Some file.ppt"). You could then
proceed to

FilePath.Open

or whatever is the right command for opening the file.

This method would solve the problem of opening via a Command bar in Jim's
method not returning the file path.

MacScript is a command available to VBA on the Mac, for running AppleScripts
in VBA. AppleScript can access virtually all aspects of the system and
Finder, and most applications (as long as they're AppleScriptable, which
most are).



--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.

> From: Jim Gordon MVP <goldkey74@WarmerThanWarmMail.com>
> Organization: I am not a Microsoft employee
> Reply-To: <goldkey74@WarmerThanWarmMail.com>
> Newsgroups: microsoft.public.mac.office,microsoft.public.mac.o ffice.powerpoint
> Date: Thu, 17 Nov 2005 00:49:57 -0500
> Subject: Re: How to display common file dialogs?
>
> Hi,
>
> FileDialog is probably a new command introduced in Visual Basic for
> Applications version 6. Office on the Mac supports VBA up to version 5.
>
> However, it is possible to display the File Open dialog box
> programmatically in VBA on the Mac.
>
> One way is to use VBA to click the File Open button on the standard
> toolbar. Check the Excecute command for command bar buttons in help for
> an example.
>
> A better way is to create a temporary toolbar, put the File Open button
> on it, then use the execute command to display the File Open dialog box.
> This way if someone has customized their standard toolbar it will still
> work.
>
> Here's some code I use to create a temporary toolbar called Animate Object:
>
> ' Create the temporary toolbar and add two command buttons to it
> Set TempBar = CommandBars.Add(Name:="AnimateObject")
> TempBar.Visible = True
>
> Application.CommandBars("AnimateObject").Controls. Add
> Type:=msoControlButton, Id:= _
> 2746, Before:=1
> Application.CommandBars("AnimateObject").Controls. Add
> Type:=msoControlButton, Id:= _
> 750, Before:=2
>
> 'Set TempBarButton =
> CommandBars("AnimateObject").Controls.Add(Type:=ms oControlButton)
> 'With TempBarButton
> '.FaceId = 2746
> '.Visible = True
> 'End With
> Set MyBar = CommandBars("AnimateObject")
> With MyBar
> .Height = 0
> .Width = 50
> .RowIndex = 3
> .Position = msoBarTop
> .Visible = False
> End With
>
> Notice that the FaceID number and the msoControlButton ID are the same
> number. You can find those numbers by finding and downloading FACEID.XLS
> (it's available from several MVP web sites - find it with Google). The
> number for File Open dialog box is 23.
>
> To get rid of the temporary command bar:
> Application.CommandBars("AnimateObject").Delete
>
> To click the first button on the command bar
> Application.CommandBars("AnimateObject").Controls( 1).Execute
>
> To click the second it would be
> Application.CommandBars("AnimateObject").Controls( 2).Execute
>
> Just to make sure everything worked OK I just successfully tested with
> this code:
>
> Sub tempbar()
> ' Create the temporary toolbar and add two command buttons to it
> Set test = CommandBars.Add(Name:="test")
> test.Visible = True
>
> Application.CommandBars("test").Controls.Add
> Type:=msoControlButton, Id:= _
> 23, Before:=1
> End Sub
>
> Sub click()
> Application.CommandBars("test").Controls(1).Execut e
> End Sub
>
> -Jim
> --
> Jim Gordon
> Mac MVP
> MVP FAQ
> <http://mvp.support.microsoft.com/default.aspx?scid=fh;EN-US;mvpfaqs>
>
>
> grendel99@yahoo.com wrote:
>> Greetings. I'm using Office X on a G4 desktop with OS version 10.4.3.
>> I have some VBA macros in PowerPoint which I know to work well on
>> Windows, and now I'm trying to use them on the Mac as well. VBA in
>> general appears to work fine, but some of my macros don't.
>>
>> The problem appears to be with common file dialogs. For example, in a
>> macro on Windows I can do something like this:
>>
>> Dim fd As FileDialog
>> Set fd = Application.FileDialog(msoFileDialogOpen)
>> fd.Show
>>
>> ...which causes a 'File Open' dialog to appear, and everything's great.
>> The trouble is, Application.FileDialog doesn't seem to even exist on
>> the Mac -- so what do I do? I can't believe there aren't standard
>> dialog types in MacOS, so there has to be some way to access them.
>>
>> Sorry if this is too elementary -- I've looked in the help file and
>> other places, all to no avail, I'm afraid. Maybe I'm just not
>> searching for the right terms. Any help would be enormously
>> appreciated.
>>
>> Thanks!
>> -DH
>>
Reply With Quote
Jim Gordon MVP
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-18-2005, 03:59 AM
Hi again,

Paul's methed is far more elegant than a pure VBA solution.

Although there's no VB6 support on the Mac, and Microsoft is likely to
drop support for VB altogether for both Mac and Windows some day-
http://news.com.com/Developers+slam+...3-5615331.html

Essentially VB is a dying thing. MacBU decided to just stick with ver 5.

However, as Paul mentioned, VBA on the Mac has a very important feature
not available for VBA on Windows: the ability to run AppleScripts within
VBA and to exchange information between the two languages.

So in this case where there is a hole in the capabilities of VBA,
AppleScript fills the gap and can live happily with VBA code.

-Jim

--
Jim Gordon
Mac MVP
MVP FAQ
<http://mvp.support.microsoft.com/default.aspx?scid=fh;EN-US;mvpfaqs>


Paul Berkowitz wrote:
> Or you could simply use the MacScript function:
>
> Dim FilePath As String
>
> FilePath = MacScript("(choose file) as string")
>
>
> That will open an OS Open dialog, to let you choose the file you want to
> open, and will return the result as a Mac colon-delimited string (such as
> "Macintosh Hard Disk:Folder 1:Folder 2:Some file.ppt"). You could then
> proceed to
>
> FilePath.Open
>
> or whatever is the right command for opening the file.
>
> This method would solve the problem of opening via a Command bar in Jim's
> method not returning the file path.
>
> MacScript is a command available to VBA on the Mac, for running AppleScripts
> in VBA. AppleScript can access virtually all aspects of the system and
> Finder, and most applications (as long as they're AppleScriptable, which
> most are).
>
>
>
Reply With Quote
Bob Greenblatt
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-18-2005, 12:53 PM
On 11/17/05 1:06 PM, in article
1132250763.916330.215310@g49g2000cwa.googlegroups. com, "grendel99@yahoo.com"
<grendel99@yahoo.com> wrote:
> Thanks for your reply, Jim, that was very good advice. I've succeeded
> in making the File Open dialog box appear using your technique, but now
> I need to return the filename(s) of the files chosen in the dialog back
> to the calling function. For example, in Windows I could do this:
>
> Dim fd As FileDialog
> Set fd = Application.FileDialog(msoFileDialogOpen)
> fd.Show
> Dim szFile as String
> szFile = fd.SelectedItems.Item(1)
>
> ...thereby storing in szFile the name of the file selected in the
>
> dialog. What would be the corresponding technique on the Mac? (I'm
> fearful you'll tell me there isn't one, since we're opening the dialog
> through a command bar.) BTW, this business of Mac's VBA only being
> version 5 is bizarre; surely Microsoft has the power to port VB 6...
>
> Many thanks!
> - DH
>
If you just want to return the file name for a file open dialog use
application.getopenfilename. This will work on BOTH Mac and windows, and
returns the full path of the file selected by the user (or FALSE if the user
cancelled). Unlike msofiledialogopen, it WILL NOT open the file, but just
pass the file name.

However, there is one ugly bug that has remained unfixed for a long time. If
the user uses the disclosure triangles to drill down folders, the returned
path to the selected file will be incorrect. However, if the user double
clicks folders to open them to drill down to get to the file, the returned
path will be correct.

--
Bob Greenblatt [MVP], Macintosh
bobgreenblattATmsnDOTcom

Reply With Quote
Steve Rindsberg
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-18-2005, 04:58 PM
> If you just want to return the file name for a file open dialog use
> application.getopenfilename. This will work on BOTH Mac and windows, and
> returns the full path of the file selected by the user (or FALSE if the user
> cancelled). Unlike msofiledialogopen, it WILL NOT open the file, but just
> pass the file name.
Hi Bob,

This sounds quite useful. Could you post a working snippet that exercises this?

I can't find anything in the Win PPT or Word object browser that suggests it's
implemented there. Or in the Mac PPT X version, for that matter.



================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================


Reply With Quote
grendel99@yahoo.com
Guest
Posts: n/a
 
Re: How to display common file dialogs?
Posted: 11-18-2005, 05:34 PM
Thanks a ton to everyone who provided such useful advice. Paul's
MacScript technique turned out to be the way to go, but Jim's VBA
solution was good too and I've filed it away for the future in case it
comes in handy. My "problem" is 100% fixed now and I've learned a lot
doing it. You guys rock!

A final thought:

Would REALBasic have been better than VB for this task? I don't know
much about REALBasic (or about VB either, for that matter -- I'm
normally a C++ engineer, but had to do some fancy things with
PowerPoint for an upcoming conference and VBA seemed to be the way to
do it), but from what I've read it's a very good language and has all
the things one might need, including MS Office support. As Mac &
Office experts, what's your opinion on this? (I ask because of
compatibility issues such as the one I posted to start with, and
because of Jim's remark that VB is dying -- should I look to REALBasic
in the future?) ...I'm sure this is a big topic that's perhaps best
suited for a new thread, but just a quick take for a newcomer like
myself? Feel free to reply to me via an email if you don't want to
post an off-topic reply to this thread.

Thanks again!
- DH

Reply With Quote
 
LinkBack Thread Tools Display Modes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Vista Common Dialogs and SharePoint schyler.jones@arcomm1.com Windows Vista Networking & Sharing 0 02-06-2008 10:12 PM
Save File Dialogs B Barley Windows Vista File Management 0 08-30-2006 02:52 AM
Common Dialogs Edit/Remember positions Sem Customize Windows XP 0 10-20-2004 01:05 AM
Dialogs don't display correctly... Slobodan Brcin \(eMVP\) Windows XP Embedded 0 08-04-2004 04:40 PM
Make file dialogs display details and by date Orrie Customize Windows XP 1 10-19-2003 08:42 PM