Problem with display a Dialog & ascertain what user pressed

  • Thread starter Poodle via OfficeKB.com
  • Start date
P

Poodle via OfficeKB.com

Hi there

I have found that the ChangeFileOpenDirectory command in 2003 is unreliable,
although I have only found one post from someone else about this. Anyway, in
order to display the File Open dialog screen at a particular path, I write
the (which I successfully collect from another part of the code) as a string
in a text file. I then collect that path (Folder_Path) and use it in my file
open command as shown below. This all works fine in various places in the
code.

In one place I need to know whether the user pressed Open of Cancel. I
believe I need to display, rather than show, the dialog in order to get the
result.

If I use the following code, it does not open at the correct place:

With Dialogs(wdDialogFileOpen)
.name = Folder_Path & "\"
.Format = wdFormatDocument
End With

Result = Dialogs(wdDialogFileOpen).Display

However, if I use the following code it does work but then I can't get the
result back.

With Dialogs(wdDialogFileOpen)
.name = Folder_Path & "\"
.Format = wdFormatDocument
.Display
End With

Can anyone tell me what I am doing wrong, please? Or if there is another way
to get the result back?

Any & all help greatly appreciated.

Many thanks.
 
J

Jay Freedman

All you're missing is assigning the return value of the .Display
method to the Result variable. Try it this way:

With Dialogs(wdDialogFileOpen)
.name = Folder_Path & "\"
.Format = wdFormatDocument
Result = .Display
End With

You should have a look at
http://www.word.mvps.org/FAQs/MacrosVBA/WordDlgHelp.htm and the other
articles linked from it.

By the way, I don't understand your reference to a text file... why
not just assign the path to a variable?

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
D

debbieprobert via OfficeKB.com

Thank you so much for that. Has worked a treat. I don't understand why it
wouldn't work outside the With statement, although I appreciate that's not as
neat any way. Perhaps it's just that life is too short to worry about
undertstanding something if you can make it work another way :)

You are right about the variable. Writing the information to a text file
came about when I had problems with ChangeFileOpenDirectory and was trying to
break the process down to find out why. The code had been working
satisfactorily in various versions of Office for many years until 2003 came
along. Writing the information away was just to prove to myself that the
code really had 'registered' the path that I wanted. I can put it back to
being a variable now.

Once again, thanks for your help which is hugely appreciated.

Jay said:
All you're missing is assigning the return value of the .Display
method to the Result variable. Try it this way:

With Dialogs(wdDialogFileOpen)
.name = Folder_Path & "\"
.Format = wdFormatDocument
Result = .Display
End With

You should have a look at
http://www.word.mvps.org/FAQs/MacrosVBA/WordDlgHelp.htm and the other
articles linked from it.

By the way, I don't understand your reference to a text file... why
not just assign the path to a variable?

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
[quoted text clipped - 34 lines]
Many thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top